Skip to content

Commit ecd10be

Browse files
committed
Reorder type inference cases
1 parent 0a1a3ec commit ecd10be

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8668,11 +8668,14 @@ namespace ts {
86688668
function inferFromObjectTypes(source: Type, target: Type) {
86698669
if (getObjectFlags(target) & ObjectFlags.Mapped) {
86708670
const constraintType = getConstraintTypeFromMappedType(<MappedType>target);
8671-
if (getObjectFlags(source) & ObjectFlags.Mapped) {
8672-
// We're inferring from a mapped type to a mapped type, so simply infer from constraint type to
8673-
// constraint type and from template type to template type.
8674-
inferFromTypes(getConstraintTypeFromMappedType(<MappedType>source), constraintType);
8675-
inferFromTypes(getTemplateTypeFromMappedType(<MappedType>source), getTemplateTypeFromMappedType(<MappedType>target));
8671+
if (constraintType.flags & TypeFlags.Index) {
8672+
// We're inferring from some source type S to an isomorphic mapped type { [P in keyof T]: X },
8673+
// where T is a type parameter. Use inferTypeForIsomorphicMappedType to infer a suitable source
8674+
// type and then infer from that type to T.
8675+
const index = indexOf(typeParameters, (<IndexType>constraintType).type);
8676+
if (index >= 0 && !typeInferences[index].isFixed) {
8677+
inferFromTypes(inferTypeForIsomorphicMappedType(source, <MappedType>target), typeParameters[index]);
8678+
}
86768679
return;
86778680
}
86788681
if (constraintType.flags & TypeFlags.TypeParameter) {
@@ -8682,14 +8685,11 @@ namespace ts {
86828685
inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(<MappedType>target));
86838686
return;
86848687
}
8685-
if (constraintType.flags & TypeFlags.Index) {
8686-
// We're inferring from some source type S to an isomorphic mapped type { [P in keyof T]: X },
8687-
// where T is a type parameter. Use inferTypeForIsomorphicMappedType to infer a suitable source
8688-
// type and then infer from that type to T.
8689-
const index = indexOf(typeParameters, (<IndexType>constraintType).type);
8690-
if (index >= 0 && !typeInferences[index].isFixed) {
8691-
inferFromTypes(inferTypeForIsomorphicMappedType(source, <MappedType>target), typeParameters[index]);
8692-
}
8688+
if (getObjectFlags(source) & ObjectFlags.Mapped) {
8689+
// We're inferring from a mapped type to a mapped type, so simply infer from constraint type to
8690+
// constraint type and from template type to template type.
8691+
inferFromTypes(getConstraintTypeFromMappedType(<MappedType>source), constraintType);
8692+
inferFromTypes(getTemplateTypeFromMappedType(<MappedType>source), getTemplateTypeFromMappedType(<MappedType>target));
86938693
return;
86948694
}
86958695
}

0 commit comments

Comments
 (0)