TypeStat icon indicating copy to clipboard operation
TypeStat copied to clipboard

Investigate a mode to *remove* unused types

Open JoshuaKGoldberg opened this issue 6 years ago • 4 comments
trafficstars

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?

JoshuaKGoldberg avatar Dec 19 '18 08:12 JoshuaKGoldberg

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?

JoshuaKGoldberg avatar Jan 09 '19 18:01 JoshuaKGoldberg

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.

JoshuaKGoldberg avatar Feb 25 '19 01:02 JoshuaKGoldberg

Additionally, moving from someProp: any to someProp: ActualObjectType would be really useful for React conversions.

JoshuaKGoldberg avatar Jul 12 '19 19:07 JoshuaKGoldberg

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

JoshuaKGoldberg avatar Dec 16 '19 14:12 JoshuaKGoldberg