Reports using legacy global functions instead of Number static 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.
Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).
@param ― number A numeric value.
isNaN(
const value:number
value);
functionisFinite(number:number):boolean
Determines whether a supplied number is finite.
@param ― number Any numeric value.
isFinite(
const value:number
value);
const
const value:number
value =
var NaN:number
NaN;
var Number:NumberConstructor
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.
NumberConstructor.isNaN(number: unknown): boolean
Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
to a number. Only values of the type number, that are also NaN, result in true.
@param ― number A numeric value.
isNaN(
const value:number
value);
var Number:NumberConstructor
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Returns true if passed value is finite.
Unlike the global isFinite, Number.isFinite doesn't forcibly convert the parameter to a
number. Only finite values of the type number, result in true.
@param ― number A numeric value.
isFinite(
const value:number
value);
const
const value:number
value =
var Number:NumberConstructor
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.
NumberConstructor.NaN: number
A value that is not a number.
In equality comparisons, NaN does not equal any value, including itself. To test whether a value is equivalent to NaN, use the isNaN function.
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.