TypeScript是否具有NaN类型? [英] Does TypeScript have a NaN type?

查看:43
本文介绍了TypeScript是否具有NaN类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TypeScript是否具有可以为变量声明的NaN类型?

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);

基本上我想知道是否可以将变量声明为NaN类型(不是未定义或为null).上面的代码段在TypeScript中不起作用,并且在TypeScript指南的基本类型"或高级类型"中都找不到.

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.

推荐答案

Typescript中没有 NaN 类型.在GitHub上有提案,但是没有实现时间表.如果您想在Typescript中看到此功能,请考虑解决该问题.

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.

这篇关于TypeScript是否具有NaN类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆