typeof 操作符可以用来获取一个变量或对象的类型
const states = {
name: 1,
block: () => {
return '123'
},
}
同一个类型的数据,直接获取它的类型给其他数据用
const blocks: typeof states = {
name: 2,
block: () => {
return '123'
},
}
keyof 检查键是否存在 获取某种类型的所有键 返回联合类型
interface Person {
name: string;
age: number;
location: string;
}
type K1 = keyof Person; // "name" | "age" | "location"
type K2 = keyof Person[]; // number | "length" | "push" | "concat" | ...
type K3 = keyof { [x: string]: Person }; // string | number