tslint-consistent-codestyle icon indicating copy to clipboard operation
tslint-consistent-codestyle copied to clipboard

prefer-const-enums: why are exports ignored?

Open Tyriar opened this issue 7 years ago • 4 comments

Enums that are exported or available in the global scope are ignored.

In https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/prefer-const-enum.md, not sure why this restriction is in place?

Tyriar avatar Apr 24 '18 00:04 Tyriar

I'm guessing it's because library depending on the exported member will not be able to see the enum. In my case I have no enums exported in my public API and would prefer const enums, an option would be good here imo.

Tyriar avatar Apr 24 '18 00:04 Tyriar

Exported enums may be used outside of the library in a dynamic way that is not supported with const enums. That could be configured by introducing a new configuration option.

But unfortunately there is another design limitation. The rule only processes one file at a time. That means it won't find dynamic uses of the enum in other files of your library.

I guess this is doable if type information is available. I'll look into this for one of the next releases.

ajafff avatar Apr 24 '18 06:04 ajafff

Hello!

Thank you for this great module.

However, I've installed this module only for prefer-const-enum rule just to find out that it's not actually working. I'm defining all my types in separate or individual files, so all my types including enums are exported and used in other JavaScript modules.

Are you planning to enable support for this use case? Thanks!

slavafomin avatar Jul 23 '18 16:07 slavafomin

+1 also would like to see this

wh1t3cAt1k avatar Oct 11 '18 17:10 wh1t3cAt1k