Skip to content

Commit 58a5f4e

Browse files
authored
fix(53722): Overloaded constructors: 'TValue' not assignable to 'string' (#53742)
1 parent c74efad commit 58a5f4e

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14543,8 +14543,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1454314543
}
1454414544
}
1454514545

14546-
const classType = declaration.kind === SyntaxKind.Constructor ?
14547-
getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent as ClassDeclaration).symbol))
14546+
const hostDeclaration = isJSDocSignature(declaration) ? getEffectiveJSDocHost(declaration) : declaration;
14547+
const classType = hostDeclaration && isConstructorDeclaration(hostDeclaration) ?
14548+
getDeclaredTypeOfClassOrInterface(getMergedSymbol((hostDeclaration.parent as ClassDeclaration).symbol))
1454814549
: undefined;
1454914550
const typeParameters = classType ? classType.localTypeParameters : getTypeParametersFromDeclaration(declaration);
1455014551
if (hasRestParameter(declaration) || isInJSFile(declaration) && maybeAddJsSyntheticRestParameter(declaration, parameters)) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== /a.js ===
2+
/**
3+
* @template T
4+
*/
5+
export class Foo {
6+
>Foo : Symbol(Foo, Decl(a.js, 0, 0))
7+
8+
/**
9+
* @constructor
10+
* @overload
11+
*/
12+
constructor() { }
13+
14+
/**
15+
* @param {T} value
16+
*/
17+
bar(value) { }
18+
>bar : Symbol(Foo.bar, Decl(a.js, 8, 21))
19+
>value : Symbol(value, Decl(a.js, 13, 8))
20+
}
21+
22+
/** @type {Foo<number>} */
23+
let foo;
24+
>foo : Symbol(foo, Decl(a.js, 17, 3))
25+
26+
foo = new Foo();
27+
>foo : Symbol(foo, Decl(a.js, 17, 3))
28+
>Foo : Symbol(Foo, Decl(a.js, 0, 0))
29+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== /a.js ===
2+
/**
3+
* @template T
4+
*/
5+
export class Foo {
6+
>Foo : Foo<T>
7+
8+
/**
9+
* @constructor
10+
* @overload
11+
*/
12+
constructor() { }
13+
14+
/**
15+
* @param {T} value
16+
*/
17+
bar(value) { }
18+
>bar : (value: T) => void
19+
>value : T
20+
}
21+
22+
/** @type {Foo<number>} */
23+
let foo;
24+
>foo : Foo<number>
25+
26+
foo = new Foo();
27+
>foo = new Foo() : Foo<number>
28+
>foo : Foo<number>
29+
>new Foo() : Foo<number>
30+
>Foo : typeof Foo
31+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @checkJs: true
2+
// @allowJs: true
3+
// @strict: true
4+
// @noEmit: true
5+
// @filename: /a.js
6+
/**
7+
* @template T
8+
*/
9+
export class Foo {
10+
/**
11+
* @constructor
12+
* @overload
13+
*/
14+
constructor() { }
15+
16+
/**
17+
* @param {T} value
18+
*/
19+
bar(value) { }
20+
}
21+
22+
/** @type {Foo<number>} */
23+
let foo;
24+
foo = new Foo();

0 commit comments

Comments
 (0)