上一篇:
TypeScript类型2(object,any,unknown,void,never,enum)https://blog.csdn.net/qq_42543244/article/details/122756084在之前的两篇中,关于类型这块,基本已经完成了,本篇补充点额外的东西;
&:同时
// let school: string & number; //错误用法: 这个写法没错误,但是到底有什么值既是string还是number?
let school: { name: string } & { peopleNumber: number };
// school = { name: '洛阳理工学院' }; //error
// school = {peopleNumber:9999}; //error
school = { name: '洛阳理工学院', peopleNumber: 9999 }; //success 同时满足
type:类型别名
/*
类型别名:
语法:
type 变量 = 值
*/
// let type1: 1 | 2 | 3 | 4;
// let type2: 1 | 2 | 3 | 4;
// type1 type2的取值都是1,2,3,4 这样重复的写有点麻烦了,这个时候就可以用上类型别名
type dictType = 1 | 2 | 3 | 4;
let type1: dictType;
let type2: dictType;
type1 = 1; //success
// type2 = 5; //error
下一篇:
TypeScript编译https://blog.csdn.net/qq_42543244/article/details/122778125