@@ -383,6 +383,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
383
383
const noImplicitAny = getStrictOptionValue(compilerOptions, "noImplicitAny");
384
384
const noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
385
385
const useUnknownInCatchVariables = getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
386
+ const inferInstanceTypeArgumentsAsConstraint = getStrictOptionValue(compilerOptions, "inferInstanceTypeArgumentsAsConstraint");
386
387
const keyofStringsOnly = !!compilerOptions.keyofStringsOnly;
387
388
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : ObjectFlags.FreshLiteral;
388
389
const exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;
@@ -8700,13 +8701,24 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
8700
8701
})!.parent;
8701
8702
}
8702
8703
8704
+ function getInstanceTypeOfClassSymbol(classSymbol: Symbol): Type {
8705
+ const classType = getDeclaredTypeOfSymbol(classSymbol) as InterfaceType;
8706
+ if (!classType.typeParameters) {
8707
+ return classType;
8708
+ }
8709
+ const typeArguments = map(classType.typeParameters, typeParameter => {
8710
+ return (inferInstanceTypeArgumentsAsConstraint) ? getBaseConstraintOfType(typeParameter) || unknownType : anyType;
8711
+ });
8712
+ return createTypeReference(classType as GenericType, typeArguments);
8713
+ }
8714
+
8703
8715
function getTypeOfPrototypeProperty(prototype: Symbol): Type {
8704
8716
// TypeScript 1.0 spec (April 2014): 8.4
8705
8717
// Every class automatically contains a static property member named 'prototype',
8706
- // the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter .
8718
+ // the type of which is an instantiation of the class type.
8707
8719
// It is an error to explicitly declare a static property member with the name 'prototype'.
8708
- const classType = getDeclaredTypeOfSymbol( getParentOfSymbol(prototype)!) as InterfaceType ;
8709
- return classType.typeParameters ? createTypeReference(classType as GenericType, map(classType.typeParameters, _ => anyType)) : classType ;
8720
+ const classSymbol = getParentOfSymbol(prototype)!;
8721
+ return getInstanceTypeOfClassSymbol(classSymbol) ;
8710
8722
}
8711
8723
8712
8724
// Return the type of the given property in the given type, or undefined if no such property exists
@@ -25135,10 +25147,10 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
25135
25147
if (symbol === undefined) {
25136
25148
return type;
25137
25149
}
25138
- const classSymbol = symbol.parent !;
25150
+ const classSymbol = getParentOfSymbol( symbol) !;
25139
25151
const targetType = hasStaticModifier(Debug.checkDefined(symbol.valueDeclaration, "should always have a declaration"))
25140
25152
? getTypeOfSymbol(classSymbol) as InterfaceType
25141
- : getDeclaredTypeOfSymbol (classSymbol);
25153
+ : getInstanceTypeOfClassSymbol (classSymbol);
25142
25154
return getNarrowedType(type, targetType, assumeTrue, /*checkDerived*/ true);
25143
25155
}
25144
25156
0 commit comments