microsoft / microsoft/TypeScript
Misleading error message when interface tries to extend constrained type parameter
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
🔎 Search Terms
"statically known members."
"could be instantiated with a different subtype of constraint 'object'."
🕗 Version & Regression Information
- This changed between versions 3.6.2 and 3.7.5
⏯ Playground Link
💻 Code
interface Example<T extends object> extends T {}
🙁 Actual behavior
I get the following message:
Interface 'Example' incorrectly extends interface 'T'.
'Example' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'.
This error message is misleading. The interface does not vary with T and since it declares no new members, is completely compatible with T.
🙂 Expected behavior
I expect a descriptive message. Prior to 3.6.2, the error message was more helpful:
An interface can only extend an object type or intersection of object types with statically known members.
This is still the error you get if the type variable T does not have the extends constraint.
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
Beginne mit dem TypeScript 3.7.5 Playground-Beispiel: interface Example extends T {}. Vergleiche dessen Diagnose mit dem Fall eines uneingeschränkten Typparameters und der Formulierung vor 3.6.2. Als erledigt gilt die Aufgabe, wenn der eingeschränkte Fall eine beschreibende Diagnose meldet, ohne das bestehende Verhalten zu beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100