当前位置:网站首页>TypeScript 变量声明 —— 类型断言
TypeScript 变量声明 —— 类型断言
2022-06-29 07:59:00 【*且听风吟】
当类型没有给出时,TypeScript 编译器利用类型推断来推断类型。
如果由于缺乏声明而不能推断出类型,那么它的类型被视作默认的动态 any 类型。
如下:
let num = 12; // 类型推断为 number
console.log("num 变量的值为 " + num);
num = "abcde";
报错:
先是声明了变量 num,并赋值为 12;
由于变量声明没有指定类型,因此,程序适用类型推断来确定变量的数据类型为 number。
接下来,试图给变量 num 赋值为 abcde 时,编译错误,因为变量在之前已经被设置为了 number 类型。
边栏推荐
- P6776-[NOI2020]超现实树
- In PHP version 7.1.13, it is found that floating-point data passes through JSON during use_ There will be precision problems after encode
- Voice annotation tool: Praat
- Voice processing tool: Sox
- Excel中VLOOKUP函数简易使用——精确匹配或近似匹配数据
- Exercise - select sort
- Memoirs of actual combat: breaking the border from webshell
- 语音信号处理-基础(一):声学基础知识
- 324. 摆动排序 II / 剑指 Offer II 102. 加减的目标值
- 语音标注自动音段对齐工具SPPAS使用笔记
猜你喜欢

Seven common sorts

What are the constraints in MySQL? (instance verification)

重磅发布 | 《FISCO BCOS应用落地指南》

VMware vcenter/esxi series vulnerability summary

常见的七大排序

Résumé des différentes séries (harmoniques, géométriques)

人民链鲍大伟:打破壁垒,建立全域数据治理共享及应用平台

Dialogue | prospects and challenges of privacy computing in the digital age

Blueprint basis

自动化运维管理平台——spug的搭建和日常使用
随机推荐
New paid Tarot calculation source code (with building tutorial)
实战回忆录从webshell开始突破边界
What are the constraints in MySQL? (instance verification)
Actual combat memoir starts from webshell to break through the border
Notes on key words in the original English work biography of jobs (VIII) [chapter six]
目标跟踪【单目标跟踪(VOT/SOT)、目标检测(detection)、行人重识别(Re-ID)】
Explain the garbage collection mechanism (GC) in JVM
U盘内存卡数据丢失怎么恢复,这样操作也可以
Why are two SQL statements that execute very fast, especially after the Union
Flutter shared_ Preferences use
sed 替换值为变量
Np5 formatted output (III)
Write time replication of hugetlbfs
Flutter 文件读写-path_provider
[6G] collation of white paper on computing network technology
PHP clear empty values in multidimensional array
各種級數(調和、幾何)總結
语音标注自动音段对齐工具SPPAS使用笔记
Speech signal processing - Fundamentals (I): basic acoustic knowledge
solidity部署和验证代理合约