numberStaticMethods
Reports using legacy global functions instead of
Numberstatic methods.
✅ This rule is included in the ts logicalStrict presets.
This rule enforces using Number static methods and properties instead of global equivalents.
The global methods isFinite() and isNaN() coerce their arguments to numbers before checking, which can lead to unexpected behavior.
Number.isNaN() and Number.isFinite() do not perform coercion and are more predictable.
Examples
Section titled “Examples”isNaN(value);isFinite(value);const value = NaN;Number.isNaN(value);Number.isFinite(value);const value = Number.NaN;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you are targeting older JavaScript environments that do not support Number.isNaN() or Number.isFinite(), you may need to continue using the global versions.
Additionally, if you intentionally rely on the type coercion behavior of the global isNaN() and isFinite() functions, disabling this rule may be appropriate.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.