- Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
Bug Report
🔎 Search Terms
variance, methods, generics
NB: I did not search very exhaustively, but I did minimize the examples, so should be pretty easy to review and close as dupe or "by design" or whatever.
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
strictFunctionTypes
⏯ Playground Link
Variance checking does not interact correctly with extends:
Variance checking does not interact correctly with "records with methods" types:
💻 Code
Variance checking does not interact correctly with extends:
typeF<outA,outB>=<XextendsA=A>(v: X)=>Bconsta: F<never,never>=v=>vconstb: F<unknown,never>=aconstresult: never=b(42)// whoopsVariance checking does not interact correctly with "records with methods" types:
typeX<outS>={x(s: S): never}consta: X<never>={x: s=>s}constb: X<unknown>=aconstwhoops: never=b.x(42)🙁 Actual behavior
In both cases the typechecker allows me to inhabit never.
🙂 Expected behavior
The typechecker should reject my incorrect variance annotations (F<out A, ...> and X<out S>) and not allow me to inhabit never.
Incidentally this came to light out of some discussion in the "forall for non-functions" issue here: #17574 (comment), but these things don't really seem materially related.
Related to #48240.