从https://github.com/Microsoft/TypeScript/pull/3622:类型交点任何
超类型折叠:一个& B等效于甲如果B是A的超类型
然而:
type a = string & any; // Resolves to any, not string!?
这十字路口解决任何。不是'任何'字符串的超类型吗?所以不应该只是字符串,由于超类型崩溃?我错过了什么?
用例这里是一样的东西:
type PropertyMap = {
prop1: {
name: "somename";
required: any;
};
prop2: {
name: "someothername";
required: never;
}
}
type RequiredOnly = {
[P in keyof PropertyMap]: PropertyMap[P] & PropertyMap[P]["required"]
}
// RequiredOnly["prop2"] correctly inferred to be never, but we've
// lost the type info on prop1, since it is now an any (but should
// have been narrowed to it's original type).
任何帮助表示赞赏。