microsoft / microsoft/TypeScript
Mixin class with type param seems to lose information about default type parameter, causing "base constructors must all have the same return type"
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
Mixin class with type param seems to lose information about default type parameter, causing "base constructors must all have the same return type"
Related:
https://github.com/microsoft/TypeScript/issues/37142
https://github.com/microsoft/TypeScript/issues/40110
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about mixins and type parameters
⏯ Playground Link
💻 Code
declare type ConstructorType<T> = abstract new () => T;
const BarableF = <TBase extends ConstructorType<Object>>(Base: TBase) => {
abstract class Barable<Bar = string> extends Base {
bar(x: string) { return x; }
}
return Barable;
};
class Bad extends BarableF(Object) {}
class Good extends BarableF(Object)<string> {}
🙁 Actual behavior
The line class Bad extends BarableF(Object) {} fails because "Base constructors must all have the same return type". If I hover over BarableF, I see the type
const BarableF: <ObjectConstructor>(Base: ObjectConstructor) => ((abstract new <**Bar**>() => BarableF<ObjectConstructor>.Barable<Bar>) & {
...;
}) & ObjectConstructor
where notably Bar has lost its default type param, which might be causing the issue.
🙂 Expected behavior
I would expect Bad to type-check without a problem, because in the Good example below it, you see that providing a type argument that is the same as the default for the type param causes things to work.
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 verlinkten TypeScript Playground und reduziere die Beispiele Bad und Good auf einen Regressionstest. Untersuche die Inferenz von Konstruktoren generischer Mixins und warum Bar's Standardtypparameter verloren geht; fertig ist die Aufgabe, wenn Bad ohne ein explizites string-Argument typgeprüft wird, während Good weiterhin funktioniert. Füge den Fall dem relevanten Compiler-Testbereich hinzu, sobald das Verhalten lokalisiert ist.
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
- 38/100