diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fcf90a11da2..2feb6b3f9c3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8668,11 +8668,14 @@ namespace ts { function inferFromObjectTypes(source: Type, target: Type) { if (getObjectFlags(target) & ObjectFlags.Mapped) { const constraintType = getConstraintTypeFromMappedType(target); - if (getObjectFlags(source) & ObjectFlags.Mapped) { - // We're inferring from a mapped type to a mapped type, so simply infer from constraint type to - // constraint type and from template type to template type. - inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); - inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); + if (constraintType.flags & TypeFlags.Index) { + // We're inferring from some source type S to an isomorphic mapped type { [P in keyof T]: X }, + // where T is a type parameter. Use inferTypeForIsomorphicMappedType to infer a suitable source + // type and then infer from that type to T. + const index = indexOf(typeParameters, (constraintType).type); + if (index >= 0 && !typeInferences[index].isFixed) { + inferFromTypes(inferTypeForIsomorphicMappedType(source, target), typeParameters[index]); + } return; } if (constraintType.flags & TypeFlags.TypeParameter) { @@ -8682,14 +8685,11 @@ namespace ts { inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target)); return; } - if (constraintType.flags & TypeFlags.Index) { - // We're inferring from some source type S to an isomorphic mapped type { [P in keyof T]: X }, - // where T is a type parameter. Use inferTypeForIsomorphicMappedType to infer a suitable source - // type and then infer from that type to T. - const index = indexOf(typeParameters, (constraintType).type); - if (index >= 0 && !typeInferences[index].isFixed) { - inferFromTypes(inferTypeForIsomorphicMappedType(source, target), typeParameters[index]); - } + if (getObjectFlags(source) & ObjectFlags.Mapped) { + // We're inferring from a mapped type to a mapped type, so simply infer from constraint type to + // constraint type and from template type to template type. + inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); + inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); return; } }