Change return value from `T2 | null | undefined` to `T2 | null` and `T2 | undefined`?
sorenlouv opened this issue · 1 comments
sorenlouv commented
I'm using idx
with Typescript and running into some minor problems with the return type.
Example:
interface User {
user?: { name?: string };
}
function getName(user: User) {
return idx(user, _ => _.user.name);
}
I would expect the return type of getName
to be string | undefined
. However the type is string | undefined | null
.
I would think that it can be inferred at compile time that null
is not a possible return type in case case, given the interface User
.
Is there any reason for this behaviour or is it a limitation with Typescript?