Fix inference from enum object type to generic mapped type

This commit is contained in:
Anders Hejlsberg 2019-04-15 15:06:44 -07:00
parent 3902ef78ae
commit cc2ea68492

View file

@ -14960,12 +14960,10 @@ namespace ts {
}
// If no inferences can be made to K's constraint, infer from a union of the property types
// in the source to the template type X.
const valueTypes = compact([
getIndexTypeOfType(source, IndexKind.String),
getIndexTypeOfType(source, IndexKind.Number),
...map(getPropertiesOfType(source), getTypeOfSymbol)
]);
inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
const indexType = source.symbol && source.symbol.flags & SymbolFlags.Enum && getEnumKind(source.symbol) === EnumKind.Literal ?
undefined : getIndexTypeOfType(source, IndexKind.String) || getIndexTypeOfType(source, IndexKind.Number);
const sourcePropsType = indexType || getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol));
inferFromTypes(sourcePropsType, getTemplateTypeFromMappedType(target));
return true;
}
return false;