function fn():string{
return '123'
}
type fnType = typeof fn; // type fnType = () => string
let a: ReturnType<fnType>;
a = '123' // string
// 错误
function fn():string{
return '123'
}
let a:typeof fn() = '123'
// 正确
let o = {
a: '123'
}
let a: typeof o.a = '123'
// 对象
let o = {
a: '123'
}
let a: typeof o['a'] = '123'
// 接口
interface O1 {
a: string
}
type Oa = O1['a']
// 类型别名
type O2 = {
a: string
}
type Ob = O2['a']
type A = {
a: string,
b:number
}
type B = A['a' | 'b'] // string | number
type C = A[keyof A] // string | number
type A<Type> = {
[Property in keyof Type]: boolean;
};
type = {
a: string;
b: number;
};
type O = A<FeatureFlags>; // {a:boolean;b:boolean}
type A<Type> = {
[Property in keyof Type]: Type[Property];
};
type A<Type> = {
[Property in keyof Type]: Type[Property];
a: string; // 错误
fn:()=>void; // 错误
};