- Test files and test functions
- Functions with decorators (which may be called indirectly)
- Public API endpoints
- Event handlers or callback functions
- Code used through reflection or dynamic imports
Overview
To simply identify code without any external usages, you can check for the absence of Symbol.usages.Filtering for Special Cases
To filter out special cases that are not explicitly referenced yet are, nonetheless, worth keeping around, you can use the following pattern:Cleaning Up Unused Variables
To remove unused variables, you can check for their usages within their scope:typescript