microsoft / microsoft/TypeScript
[exactOptionalPropertyTypes] Unexpected 'undefined' arises in error message
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
🔎 Search Terms
"not assignable", "never", "undefined", "exactOptionalPropertyTypes"
🕗 Version & Regression Information
4.3.5
'undefined' error instead of 'never' ; the value undefined is considered valid
4.4.4, 5.0.4
Expected behavior
5.1.6, 5.7.2
'undefined' error instead of 'never' ; the value undefined triggers the 'never' message
Nightly
not available when testing
⏯ Playground Link
💻 Code
--exactOptionalPropertyTypes
type T =
{ a: number, b?: never } |
{ a?: never, b: number };
const t: T = { // Types of property 'b' are incompatible. Type 'number' is not assignable to type 'undefined'
a: 0,
b: 0
};
🙁 Actual behavior
Type 'number' is not assignable to type 'undefined' is not relevant, since undefined cannot be the type of the t[b].
🙂 Expected behavior
The error should be about type 'number' not being assignable to type 'never'.
It is correctly displayed if the value undefined is used (after the regression at least).
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
Riproduci la diagnostica dal link TypeScript Playground fornito usando l'impostazione exactOptionalPropertyTypes e il tipo unione riportato. Confronta le diagnostiche tra le versioni del compilatore elencate; il lavoro è completato quando l'assegnazione di number segnala un'incompatibilità con never anziché con undefined, mentre il caso undefined mantiene il comportamento previsto.
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