Closed
Description
openedon Apr 6, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment