microsoft / microsoft/TypeScript
Conjunction of two disjunctions cause incorrect errors
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 3.3
Search Terms:
- Conjunction
Code
interface Small {
small: true,
callbackWhenSmallIsFalsy?: undefined;
}
interface NotSmall {
small?: false;
callbackWhenSmallIsFalsy: () => void;
}
interface Green {
green?: false
numberWhenGreenTrue?: undefined
}
interface NotGreen {
green: true
numberWhenGreenTrue: number;
}
type SmallProps = Small | NotSmall;
type GreenProps = Green | NotGreen;
type Props = SmallProps & GreenProps;
const try1: Props = {
green: true,
numberWhenGreenTrue: 5,
small: true
} // OK
const try2: Props = {
green: false,
numberWhenGreenTrue: 5,
small: true
} // Unexpected Error: 'callbackWhenSmallIsFalsy' is missing...
// Expected Error: 5 is not assignable to undefined for 'numberWhenGreenTrue'
const try3: Props = {
green: false,
small: true
} // OK
const try4: Props = {
green: false,
small: true,
callbackWhenSmallIsFalsy: () => 5
} // Acceptable Error: Types of property 'small' are incompatible.
// TS can't know which of the conditions to use, so this is okay. NTH: It lists multiple possible errors
Expected behavior:
in try3 I don't expect the error to be about callbackWhenSmallIsFalsy. I would expect an error about green or numberWhenGreenTrue
Actual behavior:
When the conjunction is evaluated as false, it appears that the compiler tries to force an error into the first part of the conjunction, when the falsehood is from the second part of the conjunction.
Related Issues:
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 riproducendo l’esempio di conjunction dell’issue nel TypeScript Playground, in particolare try2 e try3, e ispeziona il comportamento del compilatore per il controllo dei tipi e la diagnostica. Il lavoro è completo quando l’errore per try2 punta a numberWhenGreenTrue o green invece che a callbackWhenSmallIsFalsy, mentre gli altri casi mostrati mantengono 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