Skip to content

Generic class expression broken if duplicate constructor is removed #51078

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

Closed
JeanMeche opened this issue Oct 5, 2022 · 1 comment
Closed

Comments

@JeanMeche
Copy link
Contributor

JeanMeche commented Oct 5, 2022

Bug Report

πŸ”Ž Search Terms

Generic Class Express, constructor

πŸ•— Version & Regression Information

Tested on latest 4.8.4 & nightly

This has never worked.

⏯ Playground Link

Playground

πŸ’» Code

type Foo<T> = {
  [S in keyof T]: T[S]
}

interface IFoo {
  new <T>(): Foo<T>;
  new <T>(): Foo<T>; // KO if removed
}

const Foo: IFoo = (class {
  constructor() { }
})

const foo = new Foo();

Edit
I seems, the 2nd constructor is actually disabling a corect error, this following code work well.

type Foo<T> = {
  [S in keyof T]: T[S]
}

type Bar = {
  bar: string;
}

interface IFoo {
  new (): Bar;
}

const Foo: IFoo = (class {
  bar: string = ''
})

πŸ™‚ Expected behavior

  1. Why would the compiler trigger an error if the 2nd constructor is removed ?
  2. The empty class doesn't satisfy the constructor signature
@JeanMeche
Copy link
Contributor Author

JeanMeche commented Oct 5, 2022

This might actually be a dupe of #26631 and A. Hejlsberg gives a reason of why this happens in #50050

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant