mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
fix(53722): Overloaded constructors: 'TValue' not assignable to 'string' (#53742)
This commit is contained in:
@@ -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)) {
|
||||
|
||||
29
tests/baselines/reference/overloadTag3.symbols
Normal file
29
tests/baselines/reference/overloadTag3.symbols
Normal 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))
|
||||
|
||||
31
tests/baselines/reference/overloadTag3.types
Normal file
31
tests/baselines/reference/overloadTag3.types
Normal 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
|
||||
|
||||
24
tests/cases/conformance/jsdoc/overloadTag3.ts
Normal file
24
tests/cases/conformance/jsdoc/overloadTag3.ts
Normal 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();
|
||||
Reference in New Issue
Block a user