-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
keyof erasure in generic union types #18990
Comments
If you want to assign something to let BFieldsFailed: TFieldConfigMap<B> = Object.assign({}, AFields, {
b: { name: 'b' } // inferred as type { name: string };
}); So it warns you. The simplest fix here is to explicitly narrow the value to the type let BFieldsOkay: TFieldConfigMap<B> = Object.assign({}, AFields, {
b: { name: 'b' as 'b' }
}); Your second example uses Your third example is using So what bug do you think you're looking at? That automatic literal inference is not aggressive enough? I, myself, would like a way to tell TypeScript "infer the narrowest possible type, please" without having to redundantly write out literals as both values and types, as mentioned in #17943, but that's apparently closed as a design limitation. Is this a duplicate of #17943? |
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.2.2, 2.4.0
Code
Expected behavior:
compile flawlessly
Actual behavior:
failure to deduce types of both BFieldsFailed
and BFieldsFailedToo
I'm not sure if it is a bug in a second case.
The text was updated successfully, but these errors were encountered: