Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixin class with type param seems to lose information about default type parameter, causing "base constructors must all have the same return type" #56005

Open
boconnell opened this issue Oct 6, 2023 · 0 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@boconnell
Copy link

boconnell commented Oct 6, 2023

🔎 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:
#37142
#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

https://www.typescriptlang.org/play?ts=5.2.2#code/CYUwxgNghgTiAEAXAngBwQYQPYDsDOiMArmIljACpogA8FAfPALzxQBGBMUp8OIA7vAAUASmaMKAbgBQ0sLgLwAQrHYQQAMWbw6KvAhAAPRCBzA88bPkIkylajQDybAFbhE9ekL0gAXPAofMSZGAG9peEio9k5uRHhIKDwLFS42dRpU7U4ASxwAc0YjEzMUpIRwqKqotlghQ39cgrFQ+DhEIhgceENJeABfCOrB6raQDq7lVXSQGX6ZOWhkqeB4YtNzKbT1DSFnN1IWwcWkiwBxLCxV9dKttU0913cRGibC+FD+oA

💻 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

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Oct 6, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants