microsoft / microsoft/TypeScript
Extend "no comparison with NaN" check to cover "Number.NaN"
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
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 https://github.com/microsoft/TypeScript/issues/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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the existing check referenced in issue #49962 and locate its implementation and tests in the TypeScript repository. Extend the same behavior to the Number.NaN form, then verify that the motivating comparison is reported while runtime JavaScript output remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100