microsoft / microsoft/TypeScript
narrowing doesn't work when spreading from ternary operator
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
narrow spread ternary
🕗 Version & Regression Information
v4.5.0-dev.20210907
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Foo {
type: "foo"
foo: string
}
interface Bar {
type: "bar"
bar: number
}
declare const thing: Foo|Bar
const otherThing: Foo|Bar = { //error: Type '"foo" | "bar"' is not assignable to type '"foo"'.
type: thing.type,
...(thing.type === "foo" ? { foo: thing.foo } : { bar: thing.bar })
}
🙁 Actual behavior
error: Type '"foo" | "bar"' is not assignable to type '"foo"'.
🙂 Expected behavior
no error, since it's not possible for the object to not match either the Foo or Bar types
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 il TypeScript Playground collegato e l'esempio minimo Foo|Bar. Traccia come il type checker gestisce il narrowing all'interno di un'espressione ternaria usata in un object spread. Il lavoro è completato quando l'esempio supera il controllo dei tipi senza errori, preservando al contempo il controllo corretto dei rami di spread incompatibili.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100