pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
749 stars 49 forks source link

Add option to skip interface or type #95

Closed aspirisen closed 4 years ago

aspirisen commented 4 years ago

I think it would be good to exclude from result things that doesn't affect runtime like interface or type. For example I have a file where i export react functional component and export interface with its props, this interface can be unused but it is ok, it just in case, but if the function is unused it is important.

pzavolinsky commented 4 years ago

I agree, as long as this a behavior you can opt-in / out with a command-line switch.

Having floating types that are unused can make large code-bases hard(er) to follow (e.g. multiple copies of similarly-named interfaces with slightly different implementations).

That being said, your use-case makes perfect sense and we should support it.

mrseanryan commented 4 years ago

What is the best name for such an option?

Could be:

(default is off)

I prefer excludeCompileTimeTypes as its more general/future proof

pzavolinsky commented 4 years ago

I prefer excludeCompileTimeTypes as its more general/future proof

Agreed, but here are two more to consider:

mrseanryan commented 4 years ago

Yes - allowUnusedTypes

Is this literally only for type and interface?

(not for class for example)

pzavolinsky commented 4 years ago

Well, unlike type and interface, class is a runtime construct so pining this unused type does have runtime implications (even if only a bloated bundle).

IMO we should exclude only type and interface. That should cover the scenario that inspired this issue (the PropTypes interface for a react component).

If there is enough interest to actually allow unused classes we can talk about it in a separate issue (and a separate option).