-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compilation error with possibly nullable object #15482
Comments
It seems like for objects, the compiler properly tracks the types, as this works: export const Fun3 = (): { val1: string; val2: null } | { val1: null; val2: string } => {
return { val1: null, val2: 'string' };
};
export const Fun4 = (): string => {
const { val1, val2 } = Fun3();
if (val1) {
return val1;
}
return val2;
}; So it seems the compiler doesn't properly track and narrow tuple members in the same way it does object property members. |
The type of one of the keys is not a discriminant. in both examples, the type of Moreover, it is really hard to for the compiler to build a relationship between two variables in such a destructuring pattern. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.3.2
Code
Expected behavior:
No error
Actual behavior:
Type 'string | null' is not assignable to type 'string'.
Type 'null' is not assignable to type 'string'.
Detail
This seems like 10198, i have already new version of typescript but this is still not fixed.
The text was updated successfully, but these errors were encountered: