From https://github.com/Microsoft/TypeScript/pull/3622:
Supertype collapsing: A & B is equivalent to A if B is a supertype of A.
However:
type a = string & any; // Resolves to any, not string!?
This intersection resolves to any. Isn't 'any' a supertype of string? So shouldn't this intersection be just string, due to supertype collapsing? What am I missing?
The use case here is something like:
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).
Any help appreciated.