microsoft / microsoft/TypeScript
Couple apparent bugs with variance checking
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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:
type F<out A, out B> = <X extends A = A>(v: X) => B
const a: F<never, never> = v => v
const b: F<unknown, never> = a
const result: never = b(42) // whoops
Variance checking does not interact correctly with "records with methods" types:
type X<out S> = {
x(s: S): never
}
const a: X<never> = { x: s => s }
const b: X<unknown> = a
const whoops: 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: https://github.com/microsoft/TypeScript/issues/17574#issuecomment-1465094919, but these things don't really seem materially related.
Related to #48240.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den beiden TypeScript Playground-Reproduktionen und vergleiche die annotierten Varianzfälle, die extends und record methods betreffen. Verfolge, wie der typechecker Varianzannotationen validiert, und bestätige anschließend, dass beide inkorrekten Annotationen abgelehnt werden und kein Beispiel never inhabiten kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 28/100