Skip to content

Commit cc2ea68

Browse files
committed
Fix inference from enum object type to generic mapped type
1 parent 3902ef7 commit cc2ea68

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14960,12 +14960,10 @@ namespace ts {
1496014960
}
1496114961
// If no inferences can be made to K's constraint, infer from a union of the property types
1496214962
// in the source to the template type X.
14963-
const valueTypes = compact([
14964-
getIndexTypeOfType(source, IndexKind.String),
14965-
getIndexTypeOfType(source, IndexKind.Number),
14966-
...map(getPropertiesOfType(source), getTypeOfSymbol)
14967-
]);
14968-
inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
14963+
const indexType = source.symbol && source.symbol.flags & SymbolFlags.Enum && getEnumKind(source.symbol) === EnumKind.Literal ?
14964+
undefined : getIndexTypeOfType(source, IndexKind.String) || getIndexTypeOfType(source, IndexKind.Number);
14965+
const sourcePropsType = indexType || getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol));
14966+
inferFromTypes(sourcePropsType, getTemplateTypeFromMappedType(target));
1496914967
return true;
1497014968
}
1497114969
return false;

0 commit comments

Comments
 (0)