Fix inference for generic-typed constructor parameter when no explicit constructor is present (#47750)

* assume signature is from constructor if declaration is undefined

* add tests and baselines
This commit is contained in:
Jihn Dai
2022-02-15 18:21:44 -04:00
committed by GitHub
parent 67172e41c2
commit 1e60c8702c
5 changed files with 277 additions and 2 deletions

View File

@@ -13077,8 +13077,11 @@ namespace ts {
// object type literal or interface (using the new keyword). Each way of declaring a constructor
// will result in a different declaration kind.
if (!signature.isolatedSignatureType) {
const kind = signature.declaration ? signature.declaration.kind : SyntaxKind.Unknown;
const isConstructor = kind === SyntaxKind.Constructor || kind === SyntaxKind.ConstructSignature || kind === SyntaxKind.ConstructorType;
const kind = signature.declaration?.kind;
// If declaration is undefined, it is likely to be the signature of the default constructor.
const isConstructor = kind === undefined || kind === SyntaxKind.Constructor || kind === SyntaxKind.ConstructSignature || kind === SyntaxKind.ConstructorType;
const type = createObjectType(ObjectFlags.Anonymous);
type.members = emptySymbols;
type.properties = emptyArray;