Skip to content

Commit c8ac085

Browse files
committed
Infer non-widening literal types when type parameter constraint includes primitive types
1 parent 153c180 commit c8ac085

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12777,7 +12777,9 @@ namespace ts {
1277712777
const widenLiteralTypes = inference.topLevel &&
1277812778
!hasPrimitiveConstraint(inference.typeParameter) &&
1277912779
(inference.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), inference.typeParameter));
12780-
const baseCandidates = widenLiteralTypes ? sameMap(candidates, getWidenedLiteralType) : candidates;
12780+
const baseCandidates = widenLiteralTypes ? sameMap(candidates, getWidenedLiteralType) :
12781+
hasPrimitiveConstraint(inference.typeParameter) ? sameMap(candidates, getRegularTypeOfLiteralType) :
12782+
candidates;
1278112783
// If all inferences were made from contravariant positions, infer a common subtype. Otherwise, if
1278212784
// union types were requested or if all inferences were made from the return type position, infer a
1278312785
// union type. Otherwise, infer a common supertype.

0 commit comments

Comments
 (0)