fix(53722): Overloaded constructors: 'TValue' not assignable to 'string' (#53742)

This commit is contained in:
Oleksandr T
2023-04-21 02:32:23 +03:00
committed by GitHub
parent c74efad46e
commit 58a5f4e228
4 changed files with 87 additions and 2 deletions

View File

@@ -14543,8 +14543,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
const classType = declaration.kind === SyntaxKind.Constructor ?
getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent as ClassDeclaration).symbol))
const hostDeclaration = isJSDocSignature(declaration) ? getEffectiveJSDocHost(declaration) : declaration;
const classType = hostDeclaration && isConstructorDeclaration(hostDeclaration) ?
getDeclaredTypeOfClassOrInterface(getMergedSymbol((hostDeclaration.parent as ClassDeclaration).symbol))
: undefined;
const typeParameters = classType ? classType.localTypeParameters : getTypeParametersFromDeclaration(declaration);
if (hasRestParameter(declaration) || isInJSFile(declaration) && maybeAddJsSyntheticRestParameter(declaration, parameters)) {

View File

@@ -0,0 +1,29 @@
=== /a.js ===
/**
* @template T
*/
export class Foo {
>Foo : Symbol(Foo, Decl(a.js, 0, 0))
/**
* @constructor
* @overload
*/
constructor() { }
/**
* @param {T} value
*/
bar(value) { }
>bar : Symbol(Foo.bar, Decl(a.js, 8, 21))
>value : Symbol(value, Decl(a.js, 13, 8))
}
/** @type {Foo<number>} */
let foo;
>foo : Symbol(foo, Decl(a.js, 17, 3))
foo = new Foo();
>foo : Symbol(foo, Decl(a.js, 17, 3))
>Foo : Symbol(Foo, Decl(a.js, 0, 0))

View File

@@ -0,0 +1,31 @@
=== /a.js ===
/**
* @template T
*/
export class Foo {
>Foo : Foo<T>
/**
* @constructor
* @overload
*/
constructor() { }
/**
* @param {T} value
*/
bar(value) { }
>bar : (value: T) => void
>value : T
}
/** @type {Foo<number>} */
let foo;
>foo : Foo<number>
foo = new Foo();
>foo = new Foo() : Foo<number>
>foo : Foo<number>
>new Foo() : Foo<number>
>Foo : typeof Foo

View File

@@ -0,0 +1,24 @@
// @checkJs: true
// @allowJs: true
// @strict: true
// @noEmit: true
// @filename: /a.js
/**
* @template T
*/
export class Foo {
/**
* @constructor
* @overload
*/
constructor() { }
/**
* @param {T} value
*/
bar(value) { }
}
/** @type {Foo<number>} */
let foo;
foo = new Foo();