microsoft / microsoft/TypeScript
Type argument with a subset of the parameter constraint's optional keys incorrectly reported as unassignable to constraint
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
🔎 Search Terms
"does not satisfy the constraint" "keyof" "optional"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "constraint"
⏯ Playground Link
💻 Code
type MyType<T, U extends { [K in keyof T]?: unknown }> = U;
class MyClass<T> {
value!: MyType<T, { [K in keyof T & string]?: unknown }>;
}
🙁 Actual behavior
The following error is reported:
Type '{ [K in keyof T & string]?: unknown; }' does not satisfy the constraint '{ [K in keyof T]?: unknown; }'.
Type 'keyof T' is not assignable to type 'keyof T & string'.
Type 'string | number | symbol' is not assignable to type 'keyof T & string'.
Type 'string' is not assignable to type 'keyof T & string'.
Type 'string' is not assignable to type 'keyof T'.
Type 'keyof T' is not assignable to type 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
🙂 Expected behavior
No error should be reported because due to the keys being optional, { [K in keyof T & string]?: unknown } is a subtype of { [K in keyof T]?: unknown } for all T.
Additional information about the issue
No response
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
Reproduziere die Diagnose aus dem verlinkten TypeScript Playground-Beispiel und verfolge anschließend die Prüfung generischer Constraints für gemappte Typen mit optionalen Eigenschaften und intersected keyof keys. Die Arbeit ist abgeschlossen, wenn das Beispiel ohne Fehler kompiliert und gleichzeitig die korrekte Constraint-Prüfung für verwandte Fälle erhalten bleibt.
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
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100