question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A mixin class must have a constructor with a single rest parameter of type 'any[]'.

See original GitHub issue

TypeScript 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:open
  • Created 4 years ago
  • Reactions:34
  • Comments:17

github_iconTop GitHub Comments

12reactions
canonic-epicurecommented, Jun 25, 2021

Any hope for at least fixing the case, when mixin has no constructor? That is definitely a valid case.

9reactions
Wyctuscommented, Mar 25, 2022

What is the status of this?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found