当前位置:网站首页>Typescript -- preliminary study of variable declaration
Typescript -- preliminary study of variable declaration
2022-06-11 09:03:00 【Crmeb Zhongbang Technology】
Preface
Get to know TypeScript The basic types in , Next, of course, is the study of variable declaration .
Declare multidimensional arrays
If there is such a statement :
let arr3: number[][][]; Copy code Want to know arr3 Specific types of , The analysis steps are as follows :

You can see , Type disassembly is from right to left , Corresponding to the specific variable value, it is disassembled layer by layer from outside to inside .
Here's just an example , A person with a little experience can judge at a glance arr3 It's a three-dimensional array . however , Teaching a man to fish is better than giving him a fish , This analysis method is applicable to the analysis of most complex data types .
Property rename
In the presence of ES6 After deconstruction assignment , We can declare variables like this :
let personInfo1 = { name: " The samadhi of programming ", age:22}let {name: nameP, age: ageP} = personalInfo1; Copy code The above code declares nameP and ageP Two variables . It should be noted that : Variable declaration , The colon is not followed by a data type , Instead of the original value of the object .
If in TypeScript in , To specify nameP and ageP Data type of , It needs to be written like this :
let { name: nameP, age: ageP }: { name: string; age: number } = personInfo1; Copy code In fact, this type designation can be placed in the object declaration , Specify the type of each attribute value of the object :
let personInfo1: { name: string; age: number } = { name: " The samadhi of programming ", age: 22};personInfo1.name = 12; // Error You can't type “number” Assign to type “string”// let {name: nameP, age: ageP} = personInfo1;let { name: nameP, age: ageP } = personInfo1;nameP = 12; // Error You can't type “number” Assign to type “string” Copy code let and const Temporary dead zone of
The following code is TypeScript You can't make a mistake , However, errors will be reported in actual operation .
function foo(): number { return a1;}foo();let a1: number = 12; Copy code Actual operation error :

My own understanding is : Static compilation is only responsible for detecting whether the data type is correct , The dynamic runtime will detect syntax and logic errors , It happens that the temporary deadband is generated at runtime .
summary
That's what I'm learning TypeScript Notes and summary recorded during variable declaration .
~
~ The end of this paper , Thank you for reading !
~
Last
If you think this article is of little help to you , Point a praise . Or you can join my development communication group :1025263163 Learn from each other , We will have professional technical questions and answers
If you think this article is useful to you , Please give our open source project a little bit star:http://github.crmeb.net/u/defu Thank you for !
PHP Learning manual :https://doc.crmeb.com
Technical exchange forum :https://q.crmeb.com
边栏推荐
猜你喜欢

Iso8191 test is mentioned in as 3744.1. Are the two tests the same?

Console you don't know

openstack详解(二十三)——Neutron其他配置、数据库初始化与服务启动

机器学习笔记 - 卷积神经网络备忘清单

What if the copied code format is confused?

C language printing diamond

Port occupancy problem, 10000 ports

山东大学增强现实实验四

【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程

Matlab learning 9- nonlinear sharpening filter for image processing
随机推荐
876. intermediate node of linked list
【方案设计】基于单片机开发的家用血氧仪方案
682. 棒球比赛
openstack详解(二十一)——Neutron组件安装与配置
Why is the string class final decorated
php 上传大文件 超过40秒 服务器500
2、 Rendering camera data
20. valid brackets
206. reverse linked list
【方案开发】血压计方案压力传感器SIC160
端口占用问题,10000端口
206. reverse linked list
leveldb简单使用样例
shell脚本之sed详解 (sed命令 , sed -e , sed s/ new / old / ... )
TextView文本大小自动适配与TextView边距的去除
86. 分隔链表
SAP ABAP data types and data objects
【分享】企业如何进行施行规划?
445. adding two numbers II
【方案开发】红外体温计测温仪方案
