-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
MyGeneric<X> is sometimes not assignable to MyGeneric<Y> though X extends Y #51867
Comments
The problem here is variance measurement -- |
Tracking at #52083 |
Bug Report
🔎 Search Terms
generic extends assignable
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Error as shown when reusing the type
CaseMap[S]
instead of repeating the type it represents in the definition of MyGeneric.TS doesn't even allow a direct cast, claiming
Conversion of type 'MyGeneric<S>' to type 'MyGeneric<Size>' may be a mistake because neither type sufficiently overlaps with the other.
Note that naming the repeated type doesn't help with the error, but the motivating example doesn't provide a clear way to avoid using the map structure.
🙂 Expected behavior
No errors in the above.
MyGeneric
is actually equivalent toMyGenericWET
,takesAnySizeObject
is actually equivalent totakesAnySizeObjectWET
, andtakesOneSize
is equivalent totakesOneSizeWorks
.Possible cross-links
This might be related to #49505 which seems to focus more on type inference and chained generic functions. That refers to #30215 (a 2019 PR released in v3.4 which enabled “inference of generic function type results for generic functions that operate on other generic functions.”) Here, we don’t have generic functions operating on other generic functions, at least where “functions” is used in the JavaScript sense.
The text was updated successfully, but these errors were encountered: