Skip to content

Incorrect type inference for generic class in JavaScript #61552

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

Open
calbonaler opened this issue Apr 5, 2025 · 0 comments
Open

Incorrect type inference for generic class in JavaScript #61552

calbonaler opened this issue Apr 5, 2025 · 0 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@calbonaler
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.99.0
  • OS Version: Windows 10 Home 22H2

Steps to Reproduce:

  1. Define a generic class as below:
    /** @template T */
    class C {
      /** @param {T} a */
      constructor(a) { }
      f() { const v = new C(/** @type {T[]} */ ([])); }
    }
  2. The type of the variable v is incorrectly inferred to be C<T[][]>.

If the constructor call is outside of the class C<T> (as in the example below), the return type of the call is correctly inferred to be C<T[]>.

/** @template T */
class D {
  f() { const v = new C(/** @type {T[]} */ ([])); }
}
/** @template T; @param {C<T>} c */
const f = c => { const v = new C(/** @type {T[]} */ ([])); }
@mjbvz mjbvz transferred this issue from microsoft/vscode Apr 7, 2025
@mjbvz mjbvz removed their assignment Apr 7, 2025
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Apr 10, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Apr 10, 2025
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

3 participants