@@ -4326,10 +4326,13 @@ namespace ts {
4326
4326
4327
4327
function getTypeWithThisArgument(type: Type, thisArgument?: Type): Type {
4328
4328
if (getObjectFlags(type) & ObjectFlags.Reference) {
4329
- return createTypeReference((<TypeReference>type).target,
4330
- concatenate((<TypeReference>type).typeArguments, [thisArgument || (<TypeReference>type).target.thisType]));
4329
+ const target = (<TypeReference>type).target;
4330
+ const typeArguments = (<TypeReference>type).typeArguments;
4331
+ if (length(target.typeParameters) === length(typeArguments)) {
4332
+ return createTypeReference(target, concatenate(typeArguments, [thisArgument || target.thisType]));
4333
+ }
4331
4334
}
4332
- if (type.flags & TypeFlags.Intersection) {
4335
+ else if (type.flags & TypeFlags.Intersection) {
4333
4336
return getIntersectionType(map((<IntersectionType>type).types, t => getTypeWithThisArgument(t, thisArgument)));
4334
4337
}
4335
4338
return type;
@@ -4858,14 +4861,19 @@ namespace ts {
4858
4861
}
4859
4862
}
4860
4863
4864
+ function getApparentTypeOfIntersectionType(type: IntersectionType) {
4865
+ return type.resolvedIndexType || (type.resolvedApparentType = getTypeWithThisArgument(type, type));
4866
+ }
4867
+
4861
4868
/**
4862
4869
* For a type parameter, return the base constraint of the type parameter. For the string, number,
4863
4870
* boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
4864
4871
* type itself. Note that the apparent type of a union type is the union type itself.
4865
4872
*/
4866
4873
function getApparentType(type: Type): Type {
4867
4874
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType : type;
4868
- return t.flags & TypeFlags.StringLike ? globalStringType :
4875
+ return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>type) :
4876
+ t.flags & TypeFlags.StringLike ? globalStringType :
4869
4877
t.flags & TypeFlags.NumberLike ? globalNumberType :
4870
4878
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
4871
4879
t.flags & TypeFlags.ESSymbol ? getGlobalESSymbolType() :
0 commit comments