I think typescript:S7773 should not affect constants

Hello,

I come here following an issue telling me “Perfer Number.NaNover NaN”.
Even though the rule description clearly state that NaN or Infinity are targeted, I am not convinced constants should be affected by this rule.

I totally agree with the rule for utilities because there is a behavioral difference between their global and Number namespace versions. It prevents potential bugs.

In the case of constants, there is no behavioral difference; Number.NaN === NaN, Number.POSITIVE_INFINITY === Infinity. The only argument is the concistency. However, I think it is more a style choice; you can concistently use the Numbernamespace for functions and directly the global values for constants.

In the end, it looks like the rule is doing two different things:

  • Protecting us from the pitfalls of global utility functions
  • Enforcing a style choice for concistency (which can be debated)

Some people may be interested in only one of those. So, maybe they should be split into two separate rules.

Hi @LoicDavid, welcome to the community! :tada:

Thank you for the thoughtful report.

After reviewing it, we agree that NaN should be excluded from this rule. We’ve created JS-2012 to track the update.

Thanks again for raising this with us!
Francois