当前位置:网站首页>Typescript keyboard mapping
Typescript keyboard mapping
2022-06-11 07:59:00 【YY little monster】
1. What is a mapping type ?
Create a new type from the old type , We call it mapping type
We can go through +/- To specify whether to add or remove Read only and optional modifiers
interface TestInterface1{
name:string,
age:number
}
interface TestInterface2{
readonly name?:string,
readonly age?:number
}
type ReadonlyTestInterface<T> = {
// [P in keyof T] effect : Traverse all of the specified types key, Add to current object
// readonly [P in keyof T]: T[P]
// readonly [P in keyof T]?: T[P]
-readonly [P in keyof T]-?: T[P]
}
// take TestInterface2 Cancel read only and optional
//type MyType ={
// name:string,
// age:number
//}
type MyType = ReadonlyTestInterface<TestInterface2>
2. Because it is common to generate read-only attributes and optional attributes , therefore TS The internal has provided us with a ready-made implementation
/* read-only type MyType2 = { readonly name:string, readonly age:number } */
type MyType2 = Readonly<TestInterface1>
/* Optional type MyType3 = { name?:string, age?:number } */
type MyType3 = Partial<TestInterface1>
/* Read only optional MyType4 ={ readonly name?:string, readonly age?:number } */
type MyType4 = Partial<Readonly<TestInterface1>>
3.Pick Mapping type
Map parts of the original type to the new type
interface TestInterface {
name:string,
age:number
}
/*type MyType = { name:string, */
type MyType = Pick<TestInterface, 'name'>
4.Record Mapping type
He will map all attribute values of one type to another and create a new type
type Animal = 'person' | 'dog' | 'cat';
interface TestInterface {
name:string;
age:number;
}
type MyType = Record<Animal, TestInterface>
/*type MyType ={ person:TestInterface, dog:TestInterface, cat:TestInterface } */
let res:MyType = {
person:{
name:'zs',
age:18
},
dog:{
name:'wc',
age:3
},
cat:{
name:'mm',
age:2
}
}
边栏推荐
- Label the mask image not obtained through labelme
- Clipping and overlapping of YUV data
- Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel
- 【CodeForces908H】New Year and Boolean Bridges (FWT)
- 2021-10-17
- 2022.6.6 特长生模拟
- multi-sig SC
- Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np
- Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
- Database connection pool and bdutils tool
猜你喜欢

Image data enhancement (translation, rotation, brightness transformation, flipping, adding Gaussian noise, scaling, cropping)

Alchemy experience (model training of deep learning) the necessity of timely adjusting training parameters for some situations (the adjustment of learning rate LR is the primary) summarizes some metho

Lesson 1 about Xiaobai's C language

Xshell7 和 Xftp7要继续使用此程序,您必须应用最新的更新或者使用新版本

C language lesson 2

Tutoriel de démarrage bladed (vidéo)

About static keyword

C language - growth diary-04- preliminary exploration of local variables (local variables)

使用 COCO 数据集训练 YOLOv4-CSP 模型

C language - Growth Diary -01- count primes and sum
随机推荐
forEach 中 return 和 for 中 break
Shell Programming Notes
multi-sig SC
Dameng database startup and shutdown
C. Managing history (greedy / hashing / thinking / good questions)
Magnifying mirror rendering
Image processing operation record
SOCKET【5】- struct linger 用法
JSP technology: JSP overview, JSP basic syntax, JSP instructions, JSP implicit objects, JSP action elements
Qunhui ds918 creates m.2 SSD read / write cache
Dameng database login
Space geometry
TypeScript-unknown类型
Xshell7 and xftp7 to continue using this program, you must apply the latest updates or use a new version
Sort - select sort
[atcoder2307] tree game
2021-10-17
ConstraintLayout中使用Guideline限制控件最大宽度
TypeScript-声明合并
YUV数据的裁剪与重叠