-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Covariance, contravariance and assignability #55603
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
Methods are intentionally bivariant, this is mentioned in the FAQ:
And from the linked issue:
|
Agreed. But then, in the latter case, the missing error pops back up when the generic is specified to be |
Don't rely too much on these variance annotations, as they may produce unexpected behavior when fall back to structure checking. You can see the discussion here. |
Yes. |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
covariance
contravariance
🕗 Version & Regression Information
(Please suggest a better title 😅)
Recently Andrew Burgess posted a video related to covariance and contravariance, and also the
in
andout
keywordsNoticed issue related to assignability while playing around with the code
⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.2.2&ssl=13&ssc=1&pln=15&pc=1#code/C4TwDgpgBAUg9gIygXigbwFBShAdgRwFcJiATAQWAC4oARAQ2AgG4spgAne3AZ3oGNgASzi4AkqRo9OQ3AHNW2XPQC2EKTPmsAvqwyhIUAAocRp0PCSpLUAGTo2YU3HMganYoqgAbCADcIbxoARigAHygAJnCoAGYdPQNoAEViYgAeGAA+FAdsPCISdSgACgArGhgAShQcvzghUi85CGBLGhLGjVN5GuQcmC8AeiGcAjSIcsqqmnrG4dGWtsROyShpHrkZ2ASMDFIIfm96Dmh+UWkoMsRUoppbjMss1gOjk7OL4CgnMyELG4m9wm6RMv3+CGee3OvC++FiQKKmUQOVQ1wQDxYGGhl3wABYEY9kbkfi4-iBLBi9NjYQBWAkQEHOVxPXJoylYz5QfAANnpjLB5KJqBJzIBRVYQA
💻 Code
🙁 Actual behavior
If the methods defined in the
Queue
type (without usingin
andout
keywords) used the arrow function syntax, there are two of the four assignments which are errors.But if using the normal function syntax, only one is erroring.
🙂 Expected behavior
Consistent behaviour is expected in all cases.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: