Fix inference to indexed access type containing substitution type

This commit is contained in:
Anders Hejlsberg 2019-04-27 16:19:50 -07:00
parent 454b4280b1
commit 0759bc67a4

View file

@ -14860,6 +14860,14 @@ namespace ts {
target = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, matchingTypes);
}
}
else if (target.flags & TypeFlags.Substitution) {
target = (target as SubstitutionType).typeVariable;
}
else if (target.flags & TypeFlags.IndexedAccess && (
(<IndexedAccessType>target).objectType.flags & TypeFlags.Substitution ||
(<IndexedAccessType>target).indexType.flags & TypeFlags.Substitution)) {
target = getIndexedAccessType(getActualTypeVariable((<IndexedAccessType>target).objectType), getActualTypeVariable((<IndexedAccessType>target).indexType));
}
if (target.flags & TypeFlags.TypeVariable) {
// If target is a type parameter, make an inference, unless the source type contains
// the anyFunctionType (the wildcard type that's used to avoid contextually typing functions).
@ -14921,9 +14929,6 @@ namespace ts {
}
}
}
else if (target.flags & TypeFlags.Substitution) {
inferFromTypes(source, (target as SubstitutionType).typeVariable);
}
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// If source and target are references to the same generic type, infer from type arguments
const sourceTypes = (<TypeReference>source).typeArguments || emptyArray;