A mixin class must have a constructor with a single rest parameter of type 'any[]'.
See original GitHub issueTypeScript Version: 3.8.2
Search Terms: βA mixin class must have a constructor with a single rest parameter of type βany[]β.β
Code
export type Constructor<T = {}> = new (...a: any[]) => T;
export function DataMixin<TBase extends Constructor<{}>>(
superclass: TBase
) {
return class DataClass<TData> extends superclass {
data: TData = null;
};
}
export function QueryMixin<TBase extends Constructor<{}>>(
superclass: TBase
) {
return class QueryClass<TData> extends DataMixin<TBase>(superclass)<TData> {
query(): TData {
return this.data;
}
};
}
Expected behavior:
Iβd expect this to compile without error
Actual behavior:
error TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'.
Playground Link: Playground Link
Related Issues: https://github.com/Microsoft/TypeScript/issues/16390
Issue Analytics
- State:
- Created 4 years ago
- Reactions:34
- Comments:17
Top Results From Across the Web
why do typescript mixins require a constructor with a single ...
A mixin class must have a constructor with a single rest parameter of type 'any[]' that's a known requirement/restriction of typescript. It'sΒ ...
Read more >Documentation - TypeScript 2.2
A mixin constructor type refers to a type that has a single construct signature with a single rest argument of type any[] and...
Read more >Why Do Typescript Mixins Require A Constructor With A ...
The constructor of a mixin class (if any) must have a single rest parameter of type any[] and must use the spread operator...
Read more >The mixin pattern in TypeScript - all you need to know - Bryntum
The type of the base argument is T extends AnyConstructor<AlreadyImplements> which should be read as β βany constructor function of a class ......
Read more >A tour of the Dart language
A tour of all the major Dart language features. ... A single-line comment. ... In the code above, number is inferred to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any hope for at least fixing the case, when mixin has no constructor? That is definitely a valid case.
What is the status of this?