当前位置:网站首页>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 类型。
边栏推荐
- Voice processing tool: Sox
- ThreadLocal thread variable
- 服装产业发展趋势|供应链|智能制造
- Verilog first experience
- Sed replace value with variable
- 各种级数(调和、几何)总结
- 324. 摆动排序 II / 剑指 Offer II 102. 加减的目标值
- [eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables
- Notes on key words in the original English work biography of jobs (VIII) [chapter six]
- Blueprint basis
猜你喜欢

Matlab 用法

1284_ Implementation analysis of FreeRTOS task priority acquisition

Wallpaper applet source code double ended wechat Tiktok applet

MySQL system keyword summary (official website)
![[quantitative investment system] factor processing and installation Talib](/img/33/1b8776a392c37f4d32d3bfbb3f9fd4.png)
[quantitative investment system] factor processing and installation Talib

互斥量互斥锁

自注意力机制超级详解(Self-attention)

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

ThreadLocal thread variable

Huawei equipment is configured with small network WLAN basic services
随机推荐
网上开股票账户真的安全吗?求答案
Target tracking [single target tracking (vot/sot), target detection, pedestrian re identification (re ID)]
重磅发布 | 《FISCO BCOS应用落地指南》
Blueprint basis
表格背单词的方法
The @dynamicmemberlookup and callasfunction features in swift implement the object transparent proxy function
Message Oriented Middleware: pulsar
Why are two SQL statements that execute very fast, especially after the Union
Feature selection: maximum information coefficient (MIC) [used to measure the degree of correlation between two variables X and y, linear or nonlinear strength, commonly used for feature selection of
自动化运维管理平台——spug的搭建和日常使用
为什么两个执行很快的SQL,union之后特别慢
solidity部署和验证代理合约
Use GPU training in the cloud on the laboratory (take yolov5 as an example)
Voice annotation tool: Praat
Development trend of garment industry | supply chain | intelligent manufacturing
NP3 formatted output (I)
dcase_util教程
ThreadLocal thread variable
《乔布斯传》英文原著重点词汇笔记(七)【 chapter five】
各種級數(調和、幾何)總結