microsoft / microsoft/TypeScript
Misleading EPC error on deferred generic type when assigning any object literal, but empty object is also not assignable
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
N/A (bug report forked from #56388)
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type S = {x: 'abc'}
function f<T extends S>() {
const x: {[k in T['x']]: number} = {abc: 1} // EPC error, for any imaginable key
const y: {[k in T['x']]: number} = {} // ...but this is also a (correct!) type error
}
🙁 Actual behavior
EPC diagnostic on any non-empty object literal, but {} is also not assignable.
🙂 Expected behavior
No EPC diagnostic; should just be a straight assignability failure.
Additional information about the issue
Producing an EPC (excess property check) error for any non-empty object literal here is misleading since that ultimately implies {} would be a legal value (it is not). 5.3 exacerbates this because it removes the "X is not assignable to Y" text from EPC diagnostics, which further implies that the value would be legal if assigned indirectly (also not true; the type is generic and might have other properties).
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
Führe das verlinkte TypeScript Playground-Beispiel aus und vergleiche die Diagnosen für die nicht leeren und leeren Objekt-Literale im generic mapped-type-Fall. Verfolge das excess property checking des Compilers und seine assignability-Entscheidung für dieses Muster; erledigt ist die Aufgabe, wenn das nicht leere Literal einen regulären assignability-Fehler statt einer EPC-Diagnose erhält.
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
- 45/100