microsoft / microsoft/TypeScript
Conjunction of two disjunctions cause incorrect errors
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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:
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 damit, das Conjunction-Beispiel aus dem Issue im TypeScript Playground zu reproduzieren, insbesondere try2 und try3, und untersuche das Type-Checking- und Diagnoseverhalten des Compilers. Als erledigt gilt die Aufgabe, wenn der Fehler für try2 auf numberWhenGreenTrue oder green statt auf callbackWhenSmallIsFalsy verweist, während die anderen gezeigten Fälle ihr erwartetes Verhalten beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100