Skip to content

(Vanilla) Mixins Pattern: Base constructor must have same return type #40110

Closed
@jorenbroekema

Description

@jorenbroekema

TypeScript Version: 4.1.0-dev.20200818

Search Terms: Base constructors same return type

Code

declare type Constructor<T> = new (...args: any[]) => T;

declare class FooHost {
  static foo: string;
}

declare function FooMixin<T extends Constructor<HTMLElement>>(superclass: T): T & Constructor<FooHost> & typeof FooHost


class Foo extends FooMixin(HTMLElement) { }

The reason I do & typeof FooHost at the end of FooMixin is because I need to be able to access the static property foo of the FooMixin's host class. This part works. But it creates a new error:

Base constructors must all have the same return type

What is important here to note is that in my project I use allowJs + checkJs so I have to find a way that doesn't include me being forced to do something like:

class Foo extends FooMixin(HTMLElement)<Args> { }

Because I can't, my implementation is in JavaScript (where the FooMixin is applied).

Expected behavior:

No error

Actual behavior:

Base constructors must all have the same return type

Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20200818#code/CYUwxgNghgTiAEAXAngBwQYQPYDsDOiMArmIljADwAqAfPALzw4gDu8AFAHTewDmeALnhQcyANoBdAJQM6VANwAoRaEiwEavHngAxLFgASWAvADei+PAJREASzBWwWdMACiEEAFsQORIKuEtji8SgC+yqrQcPAAZkQ4pLa4uvoAsrYAHkHU8CAZiD7A2tj4hCRklAZUqQAy7l4+iDQ07HhE6DCa-lRSQlTwAGTwJQTEpOQUeobGTYNIaCBYMSnTBMqKXSu5+YXaU+lZOOxVtfXevjKm8KFAA

Metadata

Metadata

Assignees

Labels

RescheduledThis issue was previously scheduled to an earlier milestoneWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions