当前位置:网站首页>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 类型。
边栏推荐
- 新版付费塔罗牌测算源码 (附带搭建教程)
- [eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables
- ThreadLocal thread variable
- 消息中间件:pulsar
- MySQL statistics by day / week / month / quarter / half year / year
- P4769-[NOI2018]冒泡排序【组合数学,树状数组】
- 1284_ Implementation analysis of FreeRTOS task priority acquisition
- Automatic operation and maintenance management platform - construction and daily use of SPuG
- Notes mosaïque
- Talking about Nacos configuration center from Nacos client
猜你喜欢

Taro 介绍
![Speech synthesis: overview [generation task of unequal length sequence relation modeling]](/img/13/bd9def50f0efde49b622d139f63a83.png)
Speech synthesis: overview [generation task of unequal length sequence relation modeling]
![[hcie TAC] question 5-2](/img/a5/308aa2cced4cba59354c576a07e3c0.jpg)
[hcie TAC] question 5-2

Interprocess communication (IPC)

New paid Tarot calculation source code (with building tutorial)

壁纸小程序源码双端微信抖音小程序

1284_ Implementation analysis of FreeRTOS task priority acquisition

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

使用adb命令调试夜神模拟器

Huawei equipment is configured with medium-sized network WLAN basic services
随机推荐
标准|中国支付清算协会发布首个隐私计算金融规范
MySQL statistics by day / week / month / quarter / half year / year
壁纸小程序源码双端微信抖音小程序
Talking about Nacos configuration center from Nacos client
NP5 格式化输出(三)
【LoRaWAN节点应用】安信可Ra-08/Ra-08H模组入网LoRaWAN网络的应用及功耗情况
各種級數(調和、幾何)總結
P6772 [noi2020] gourmet (matrix fast power)
Automatic operation and maintenance management platform - construction and daily use of SPuG
Hook 简介
Dialogue | prospects and challenges of privacy computing in the digital age
关于SQL语句的大小写
Set up Jenkins environment and automatically associate packaged project jars for automatic release
互斥量互斥锁
x86和x64的区别
图文详解JVM中的垃圾回收机制(GC)
Using method and de duplication of distinct() in laravel
Taro 介绍
What does Ali's 211 mean?
Explain the garbage collection mechanism (GC) in JVM