TypeStat
TypeStat copied to clipboard
Investigate a mode to *remove* unused types
How interesting! Idea courtesy of @sqs (superset of #34). Could TypeStat be used to remove unused types across a code base instead of adding missing ones in?
Some thoughts as part of the NPM milestone...
- This issue is important because --fixNoImplicitAny adds a lot of types that later on become unnecessary
- Object.keys(someObject).map((key: string | number) => {...}) seems unnecessary - it's also buggy if it infers string | number
- How to tell, for a given location, what its inferred type would be without its declaration?
- A lot of added parameter types, for example ones added to .filter/.map, end up being unnecessary
- Is there a way to get what the type would be if inferred from a variable/parameter/etc. that has a declaration?
A few existing mutators that will need to have this added:
- Returns
- Variable declarations
- Parameters
I'll take on this issue, since it's pretty big and might involve a lot of architecture changes.
Additionally, moving from someProp: any to someProp: ActualObjectType would be really useful for React conversions.
Thinking more on this, I see there being two fixers that could be thought of here:
- Removing inferable types, like no-inferrable-types
- Narrowing unnecessarily wide types, as discussed above