ts-unused-exports icon indicating copy to clipboard operation
ts-unused-exports copied to clipboard

Add option to ignore exported names used only in same file

Open emlai opened this issue 6 years ago • 4 comments

Currently ts-unused-exports will emit an error about FooProps if it's not imported in another file:

export interface FooProps {
  // ...
}

class Foo extends React.Component<FooProps> {
  // ...
}

I'd like to have a command-line option to change the behavior so that no error would be emitted for exported names that are only used in the same file where they're declared in.

One use case would be to allow my IDE (WebStorm) to offer auto-completion and auto-import if I need to use FooProps in another file in the future, without having to edit the declaration of FooProps first. FooProps not being exported seems to prevent WebStorm from providing auto-completion and auto-import for it in other files.

emlai avatar Oct 26 '18 08:10 emlai

Agreed. Especially since the main use for this tool is to detect unused code.

vivmaha avatar Oct 02 '19 16:10 vivmaha

@emlai if it helps, there is now a feature to disable errors for a particular line:

// ts-unused-exports:disable-next-line
export interface FooProps {
  // ...
}

mrseanryan avatar Oct 27 '19 19:10 mrseanryan

How to name the option?

What about:

  • --onlyReportDeadCode
  • --ignoreIfUsedLocally
  • --ignoreLocallyUsed

(I like the last one)

mrseanryan avatar Nov 23 '19 06:11 mrseanryan

I like --ignoreLocallyUsed too.

emlai avatar Nov 23 '19 09:11 emlai

Released in 9.0.5 !

thank you to @DLeyland for implementing this feature 🥇

mrseanryan avatar Jun 24 '23 16:06 mrseanryan