You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
strictNullChecks safeguards against null and undefined, but not NaN #21279
// simple convertionletn: number=Number("not-a-number")// could be NaN// function that returns NaNfunctioncouldBeNaN(x: any): number{if(typeofx==="number"){returnx;}returnNaN}n=couldBeNaN("not-a-number")// will return NaN
Expected behavior:
A safeguard against NaN as there is for null and undefined.
// simple convertionletn: number|NaN=Number("not-a-number")// enforced check// function that returns NaNfunctioncouldBeNaN(x: any): number|NaN{if(typeofx==="number"){returnx;}returnNaN}n=couldBeNaN("not-a-number")// will return NaN, but it's okay
Hence NaN isn't a type in TypeScript, this isn't possible.
Actual behavior:
NaN passes as a regular number although it is the direct opposite (yes, I know it is defined as such in the ECMAScript-standard, but nonetheless, it almost always hits you unexpected).
Strict null checks isn't about NaN because NaN isn't null (or undefined). If you'd like to write a suggestion proposal, please follow the guidelines for that.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
RyanCavanaugh commentedon Jan 18, 2018
Strict null checks isn't about NaN because NaN isn't null (or undefined). If you'd like to write a suggestion proposal, please follow the guidelines for that.
typescript-bot commentedon Feb 1, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.