-
Notifications
You must be signed in to change notification settings - Fork 12.8k
why doesn't this work? #6538
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
Comments
I tried to write an explanation, but the explanation was the same as the error message. Are you asking why type predicates must be assignable to their corresponding parameter types? Or something else? |
Here's a simplified example: interface Animal {
animal;
}
interface Dog extends Animal {
dog;
}
interface Car {
car;
}
let thing: Dog | Car;
// Get a similar error here
function isAnimal(x: Car | Dog): x is Animal {
return "animal" in x;
} Basically we're trying to tell you that it's nonsensical to say That said, it sounds like we should have a better error message here. See #6540. |
[Assuming that the question is why the assignability check failed.] The error message actually doesn't make it clear that the compiler tried to assign I wouldn't call @DanielRosenwasser's example simplified so much as shifting the root cause of assignability failure from intersection ( |
@RyanCavanaugh I hear you, give me the number of the issue that deals with it. Isn't If so how is
|
The difference is the assignability of intersection versus union: declare var n: Named;
let xnamed: X & Named = n;
|
but from a common sense stand point situation where I ask whether |
The text was updated successfully, but these errors were encountered: