-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Parameter not matching union type not recognized when passed by reference #32270
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 agree the error message is very misleading, see discussion starting here: #32158 (comment) Here's a pretty good explanation (IMO) of why |
Ah, I wasn't aware of this behavior! Thank you for the quick response! |
@mr-flannery Yeah, under pervasive structural typing, it’s the only behavior that makes sense, because otherwise you wouldn’t be able to have subclasses at all. |
TypeScript Version: 3.3.3333, 3.4.2, 3.4.5, 3.5.2, 3.6.0-dev.20190704
Search Terms: union, union + object, union + object + bug
Code
Expected behavior:
tsc
reports two errors, one for the last two lines respectively, as the parameters passed are essentially the same.Actual behavior:
tsc
only reports the second to last line as error, not the last one (or differently: if I comment the second to last line out,tsc
does not fail, though it should)Playground Link: https://www.typescriptlang.org/play/index.html#code/JYOwLgpgTgZghgYwgAgILIN4ChnLgLmQGcwpQBzAbiwF8stRJZEUAhTHZAI0JLJCq16CAPYgSyGCGQBeZAAoADnChwAtoXQAfZKwCUsgHzJlqtdSyjxYZCK4ArWZjyEAREQAmMVwBpkCN09vZBoLKXkMF2R3D1cQvWpwyJ5ozziaBKwkqJjfbkCYcnTM7IJUrzyA8uCMxJB5O3tMoA
Thank you very much!
The text was updated successfully, but these errors were encountered: