Microsoft/TypeScript
Auf GitHub ansehenIncorrect type inference for generic class in JavaScript
Open
#61.552 geöffnet am 5. Apr. 2025
BugDomain: check: Type InferenceHelp Wanted
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
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:
- Define a generic class as below:
/** @template T */ class C { /** @param {T} a */ constructor(a) { } f() { const v = new C(/** @type {T[]} */ ([])); } } - The type of the variable
vis incorrectly inferred to beC<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[]} */ ([])); }