-
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
Bug with type discrimination and string literal types. #13628
Comments
This issue have been around for a while, it boils down to this: const obj = {b: 'A'};
type A = 'A';
const a: A = obj.b; // ---> [ts] Type 'string' is not assignable to type '"A"'. Not much can be done here. typing |
I understand why your code doesn't work, but I still don't see why mine doesn't, as I have explicitly given the type of If I wrote |
Right, sorry, I didn't initially understand the issue you reported. I think what you expect the compiler to do is valid. This is a bug indeed 👍 |
Duplicate of #13580 |
The following code gives an error on the assignment to x:
There are multiple weird things that get rid of the error, including:
{ key: "a", name: string }
to{ key: "a" }
.name: "A"
toname: "A" as Bar
The text was updated successfully, but these errors were encountered: