当前位置:网站首页>Typescript type alias
Typescript type alias
2022-06-11 07:59:00 【YY little monster】
Details visible
1. What is a type alias ?
A type alias is a new name for a type , But they all represent the same type
for example : Your real name is Zhang San , Your nickname is Xiao San , Xiao San is the alias of Zhang San , Both Zhang San and Xiao San mean the same person
1. to string Type has an alias called MyString, So in the future, whether it is MyString still string All means string
type MyString = string;
let value:MyString;
value = 'abc';
value = 123;
value = false;
2. Type aliases can also use generics
type MyType<T> = {
x:T, y:T};
let value:MyType<number>;
value = {
x:123, y:456};// because T yes number, It can only be number
value = {
x:'123', y:456};// Report errors
value = {
x:false, y:456};// Report errors
3. Use yourself in a property of a type alias type
type MyType = {
name:string,
// It is generally used to define some tree structures or nested structures
children?:MyType
}
let value:MyType = {
name:'one',
children:{
name:'one',
children:{
name:'one',
}
}
}
4. Interface and type aliases are compatible
type MyType = {
name:string
}
interface MyInterface {
name:string
}
let value1:MyType = {
name:'lnj'};
let value2:MyInterface = {
name:'zs'};
value1 = value2;
value2 = value1;
边栏推荐
- TypeScript-可辨识联合
- Long dialogue in June 2017
- 放大镜子效果图
- String Simulation Implementation
- Label the mask image not obtained through labelme
- ConstraintLayout中使用Guideline限制控件最大宽度
- Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np
- C- print 99 multiplication table
- Login and parameterization of interface test
- [atcoder1984] wide swap
猜你喜欢

C- print 99 multiplication table

C language - Growth Diary -02- function

C language to achieve three piece chess (not artificial mental retardation ha ha ha)

如何做好空状态设计?来看这份全面总结

Crawl Baidu Baipin dynamic page
![[untitled] Weng_ C lesson 1](/img/4e/41876093ef6b6a38909832f89e1495.jpg)
[untitled] Weng_ C lesson 1

C# 微信上传Form-data

C language - Growth Diary -01- count primes and sum

Selenium click the floating menu and realize the functions of right mouse button
![[atcoder2306] rearranging (topology)](/img/b3/38589a07a7c26bea8ed154ab794760.png)
[atcoder2306] rearranging (topology)
随机推荐
2021-10-17
[codeforces1019e] raining season
学习《缠解论语》
SOCKET【5】- struct linger 用法
嵌入式软件面试问题总结
使用特殊字符拼接字符串“+“
Three expressions of integers and their storage in memory
Method summary of creating deep learning model with keras/tensorflow 2.9
C language lesson 2
Modular linear equations (Chinese remainder theorem + general solution)
2021-11-05 definition of cache
Semiconductor memory classification
[atcoder1998] stamp Rally
Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np
Shell编程笔记
[atcoder2306] rearranging (topology)
Lesson 1 about Xiaobai's C language
Label the mask image not obtained through labelme
签到体系设计:签到功能该怎么画
Record a murder case caused by ignoring the @suppresslint ("newapi") prompt