Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does TypeScript have a NaN type? [duplicate]

Does TypeScript have a NaN type that I could declare for a variable?

For example, if I was to create a variable like this:

const number: number = parseInt('123', 10);

Could I change it to be more accurate, like so:

const number: number | NaN = parseInt('123', 10);

Basically I want to know if I can declare a variable as a NaN type (not undefined or null). The above snippet doesn't work in TypeScript and I can't find it listed in either the Basic or Advanced Types within TypeScript's guides.

like image 498
Kyle Avatar asked Jan 01 '19 23:01

Kyle


1 Answers

There is no NaN type in Typescript. There is a proposal for this on GitHub but there is no timeline for implementation. Consider upvoting the issue if you want to see this feature in Typescript.

like image 117
Titian Cernicova-Dragomir Avatar answered Sep 21 '22 13:09

Titian Cernicova-Dragomir