
type Test = number[][number]; // Test will be inferred to 'number' as the above image show.为什么number[]是带有number签名的索引签名类型?
发布于 2020-05-11 02:26:55
这是一种将不同类型的值合并的方法。
它等同于:有一个数字数组,我们称之为[number],这意味着给我们一个属于数字键的值类型的并集,因为它是一个数字数组,结果是number。
type TestObject = {
test1: string;
test2: number;
};
// union of all keys is string | number
type TestValueUnion = TestObject[keyof TestObject];
// 'test1' | 'test2'
type TestKeyUnion = keyof TestObject;https://stackoverflow.com/questions/61716596
复制相似问题