Open
Description
Suggestion
π Search Terms
x === Number.NaN
disallow comparing with Number.NaN
β Viability Checklist
My suggestion meets these guidelines:
- [?] This wouldn't be a breaking change in existing TypeScript/JavaScript code - this would break code containing the error
- β This wouldn't change the runtime behavior of existing JavaScript code
- β This could be implemented without emitting different JS based on the types of the expressions
- β This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- β This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
Extend check added for #49962 to include Number.NaN
in addition to global NaN
.
π Motivating Example
function useVersionNumber(value: string) {
let versionNumber = Number(value);
if (versionNumber === Number.NaN) {
return;
}
console.log(versionNumber + 1);
}
π» Use Cases
Catching a developer error (incorrect NaN handling).