-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
I am not sure that this is a bug but it did behave in a way that I did not expect which is why I filed a new issue. If this is not a bug it should probably be closed and continued in earlier issues like #17678
TypeScript Version: 2.8.1
Search Terms:
Mapped types, never, filter, conditional types, Exclude, Omit, Pick
Code
type Fruit = { name: string };
type Apple = Fruit & { cultivar: string };
type Fruits = {
banana: Fruit;
alice: Apple;
gala: Apple;
};
type Apples = {
[T in keyof Fruits]: Fruits[T] extends Apple ? Fruits[T] : never
};Expected behavior:
I expected Apples to have type
{
alice: Apple;
gala: Apple;
}Actual behavior:
Apples have the type
{
banana: never;
alice: Apple;
gala: Apple;
}Having an object with a never key is quite strange to me. How would that object ever be created?
Related Issues:
If this have worked as expected #17678 would be already be supported. That issue is marked as a duplicate and linked to #12424 and #17636 but I am not sure I see the direct relation there to be honest.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed