符号
&
type A = {
name: String;
}
type B = {
age: number;
}
type Person = A & B;
let jack: Person = {
name: 'jack',
age: 20,
}
|
type A = string | number;
let a: A = 'hello';
let b: A = 12;
? 【ESnext规范】
let obj = {}
obj.a;
obj?.b;
obj?.['c'];
?? 【短路属性】
只检验左侧是否为undefined或null
注意0、false会产生短路
console.log(undefined ?? 2);
console.log(null ?? 3);
console.log(0 ?? 3);
console.log(false ?? 3);
! 【后缀操作符】
type A = string | undefined | null;
function showType(args: A) {
let str1: string = args;
let str2: string = args!;
}
reat基础类型
typeof
instaceofΩ
keyof
O[K]
[K in O]
+、-、readonly
X ? Y : Z
!
=
as
is