diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 001e300bbc7..080637363ed 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7603,10 +7603,12 @@ namespace ts { } return; } - // Find each target constituent type that has an identically matching source - // constituent type, and for each such target constituent type infer from the type to - // itself. When inferring from a type to itself we effectively find all type parameter - // occurrences within that type and infer themselves as their type arguments. + // Find each source constituent type that has an identically matching target constituent + // type, and for each such type infer from the type to itself. When inferring from a + // type to itself we effectively find all type parameter occurrences within that type + // and infer themselves as their type arguments. We have special handling for numeric + // and string literals because the number and string types are not represented as unions + // of all their possible values. let matchingTypes: Type[]; for (const t of (source).types) { if (typeIdenticalToSomeType(t, (target).types)) { @@ -7616,8 +7618,7 @@ namespace ts { else if (t.flags & (TypeFlags.NumberLiteral | TypeFlags.StringLiteral)) { const b = getBaseTypeOfLiteralType(t); if (typeIdenticalToSomeType(b, (target).types)) { - (matchingTypes || (matchingTypes = [])).push(t); - matchingTypes.push(b); + (matchingTypes || (matchingTypes = [])).push(t, b); } } }