当前位置:网站首页>Let you understand the main points of typescript in vernacular (III)
Let you understand the main points of typescript in vernacular (III)
2022-07-21 20:44:00 【Han Zhenfang】
Three object scene
General object .( It doesn't include methods )
Same as before , Let's not directly constrain what's in the object , There will always be data before type restrictions .
At this point, go back and add type constraints .( Specifically demonstrated an error type )
There's another problem here , Here we use semicolons to separate the types of each attribute . It's not necessary , You can limit the type of attribute by multiline constraints .
Object containing method
Four . Interface interface
Interface scenario 1
As usual , Add specific constraints to existing data and then go back . You can use it here Function
This keyword defines the attribute value of an object as a function .
Still use colons :
Keyword to constrain .
Scenario 2 of interface ( Inherit extends)
For example, we now have an extra interface
To constrain new objects
But we found that ,person2Style
This constraint format is the same as the previous one person1Style
Many are the same , Is there any way we can directly reuse the same , Add what you want separately ? It can be used here extends
Keyword to implement . It is also relatively easy to implement , If there are no additional attributes you want to add , Then we can
Four . Special expansion of objects ( Yuan Zu )
Just heard this word, I was stunned , Martial arts novel yuan Taizu ?
In fact, after in-depth understanding, you will know that it is just to limit the number of your array and the type of the corresponding value of the corresponding index position . for instance , For example, I now have an array of numeric types , as follows :
It's the same as writing data , Count the number of data in the array , Properties and values are constrained .
5、 ... and . Enumeration type enum
This attribute actually specifies some constants used . The simplest example :
We now have a function , We already know that it accepts string parameters : If we write like this
It seems that some goals have been achieved , But we just want it to accept On (up) Next (down) Left (left) Right (right)
Parameters , Then we can use enum
, Use it to define some constants .
We give changeDirection
The parameters of this function are defined as Direction
This enum
type ,
Then this is the constraint
And you can call this... Like an object enum
type , as follows :
边栏推荐
猜你喜欢
Uniapp customized navigation bar buttons and button click events
数组去重的简单方法(不含引用类型)
Solve the problem that Safari browser blocks window open
利用vscode插件 coderunner 编译运行 typescript,当输出有中文的时候,出现乱码
uniapp自定义导航栏按钮及按钮点击事件
Using tailwind on Google browser, the button will have a blue background
XML parsing
Koa2快速搭建服务器
Crud of MySQL
QML implements CSDN search box with irregular rounded corners
随机推荐
在控制台输出语句
Handwriting promise
Lazy loading of pictures
[recursive] Ackerman function
How to share files over IP
边界层积分方程与马兰格尼效应
MySQL functions
npm相关资料
js页面的跳转以及接收参数
10. [file opening format and its determination of whether to open]
利用vscode插件 coderunner 编译运行 typescript,当输出有中文的时候,出现乱码
图片横向瀑布流
Reset Form
Available parameters are [list] error in batch upload
Cannot read property mode of undefined
Read the manuscript in pieces
Don't pull it today, don't pull it, read it in pieces
[C language] 0.5 times the speed to explain the interesting C language playing methods of the century war
Click the back button to return to the previous page
Format time