当前位置:网站首页>Typescript distributed condition type
Typescript distributed condition type
2022-06-11 07:59:00 【YY little monster】
1. Condition type ( Three mesh operation )
Judge whether the previous type is the latter type or inherits from the latter type
If yes, it returns the first result , If not, return the second result
grammar : T extends U ? X : Y;
type MyType<T> = T extends string ? string : any;
type res = MyType<boolean>//res = any
2. Distributed condition type
When the detected type is a union type , This condition type is called a distributed condition type
type MyType<T> = T extends any ? T : never;
//res=string|number|boolean
type res = MyType<string | number | boolean>;
3. from T Weeding can be assigned to U The type of . Exclude
type MyType<T, U> = T extends U ? never : T;
//res=tring | boolean
type res = MyType<string | number | boolean, number>
//res=tring | boolean
type res = Exclude<string | number | boolean, number>
4. extract T Can be assigned to U The type of . Extract
//res = string | number
type res = Extract<string | number | boolean, number | string>
5. from T Middle elimination null and undefined. NonNullable
//res=string | boolean
type res = NonNullable<string | null | boolean | undefined>
6. Get function return value type . ReturnType
//res=number
type res = ReturnType<(()=>number)>
7. Get the tuple type composed of constructor parameters of a class . ConstructorParameters
class Person {
constructor(name:string, age:number){
}
}
//res = [name:string, age:number]
type res = ConstructorParameters<typeof Person>;
8. Get the tuple type composed of the parameter types of the function . Parameters
function say(name:string, age:number, gender:boolean) {
}
//res = [string, age:number, gender:boolean]
type res = Parameters<typeof say>;
边栏推荐
- 空间几何
- 【CodeForces908H】New Year and Boolean Bridges (FWT)
- C# 微信上传Form-data
- C language lesson 2
- Record a murder case caused by ignoring the @suppresslint ("newapi") prompt
- 签到体系设计:签到功能该怎么画
- Return in foreach and break in for
- 【AtCoder2304】Cleaning
- Qunhui ds918 creates m.2 SSD read / write cache
- Simple use of string
猜你喜欢

Selenium click the floating menu and realize the functions of right mouse button

Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases

2022.6.7 special student simulation
![[untitled] Weng_ C lesson 1](/img/4e/41876093ef6b6a38909832f89e1495.jpg)
[untitled] Weng_ C lesson 1

Xshell7 and xftp7 to continue using this program, you must apply the latest updates or use a new version

Crawl Baidu Baipin dynamic page

Black Qunhui dsm7.0.1 physical machine installation tutorial

Qunhui ds918 creates m.2 SSD read / write cache

Batch splice string

Training yolov4 CSP model using coco dataset
随机推荐
Shell Programming Notes
Selenium click the floating menu and realize the functions of right mouse button
Summary of force deduction questions
860. lemonade change
Black Qunhui dsm7.0.1 physical machine installation tutorial
[atcoder2307] tree game
Tutoriel de démarrage bladed (vidéo)
【CodeForces908H】New Year and Boolean Bridges (FWT)
彻底记住ImageView的background和src的区别
嵌入式软件面试问题总结
C language - Growth Diary -02- function
图数据库无缝集成Tushare接口
TypeScript-命名空间
Socket [5] - struct linker usage
C. Manipulating History(贪心/哈希/思维/好题)
Image processing operation record
134. gas station
C# 微信上传Form-data
TypeScript-unknown类型
TypeScript-null和undefined