microsoft / microsoft/TypeScript
Couple apparent bugs with variance checking
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con le due riproduzioni di TypeScript Playground e confronta i casi di varianza annotati che coinvolgono extends e record methods. Traccia il modo in cui il typechecker convalida le annotazioni di varianza, quindi conferma che entrambe le annotazioni errate vengano rifiutate e che nessun esempio possa abitare never.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 28/100