@@ -9286,8 +9286,10 @@ namespace ts {
9286
9286
return type;
9287
9287
}
9288
9288
9289
- function getRegularTypeOfLiteralType(type: Type) {
9290
- return type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral ? (<LiteralType>type).regularType : type;
9289
+ function getRegularTypeOfLiteralType(type: Type): Type {
9290
+ return type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral ? (<LiteralType>type).regularType :
9291
+ type.flags & TypeFlags.Union ? getUnionType(sameMap((<UnionType>type).types, getRegularTypeOfLiteralType)) :
9292
+ type;
9291
9293
}
9292
9294
9293
9295
function getLiteralType(value: string | number, enumId?: number, symbol?: Symbol) {
@@ -12774,11 +12776,11 @@ namespace ts {
12774
12776
// all inferences were made to top-level occurrences of the type parameter, and
12775
12777
// the type parameter has no constraint or its constraint includes no primitive or literal types, and
12776
12778
// the type parameter was fixed during inference or does not occur at top-level in the return type.
12777
- const widenLiteralTypes = inference.topLevel &&
12778
- !hasPrimitiveConstraint( inference.typeParameter) &&
12779
+ const primitiveConstraint = hasPrimitiveConstraint( inference.typeParameter);
12780
+ const widenLiteralTypes = !primitiveConstraint && inference.topLevel &&
12779
12781
(inference.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), inference.typeParameter));
12780
- const baseCandidates = widenLiteralTypes ? sameMap(candidates, getWidenedLiteralType ) :
12781
- hasPrimitiveConstraint(inference.typeParameter) ? sameMap(candidates, getRegularTypeOfLiteralType ) :
12782
+ const baseCandidates = primitiveConstraint ? sameMap(candidates, getRegularTypeOfLiteralType ) :
12783
+ widenLiteralTypes ? sameMap(candidates, getWidenedLiteralType ) :
12782
12784
candidates;
12783
12785
// If all inferences were made from contravariant positions, infer a common subtype. Otherwise, if
12784
12786
// union types were requested or if all inferences were made from the return type position, infer a
0 commit comments