@@ -15261,27 +15261,29 @@ namespace ts {
15261
15261
boolean. We know that number cannot be selected
15262
15262
because it is caught in the first clause.
15263
15263
*/
15264
- const isTypeUnknown = type.flags & TypeFlags.Unknown;
15265
- const isTypeAny = type.flags & TypeFlags.Any;
15266
- const getTypeFromName = (text: string) =>
15267
- (text === "function" && !isTypeAny) ? globalFunctionType :
15268
- (text === "object" && isTypeUnknown) ? getUnionType([nonPrimitiveType, nullType]) :
15269
- (typeofTypesByName.get(text) || neverType);
15264
+ const getTypeFromName = (text: string) => {
15265
+ switch (text) {
15266
+ case "function":
15267
+ return type.flags & TypeFlags.Any ? type : globalFunctionType;
15268
+ case "object":
15269
+ return type.flags & TypeFlags.Unknown ? getUnionType([nonPrimitiveType, nullType]) : type;
15270
+ default:
15271
+ return typeofTypesByName.get(text) || unknownType;
15272
+ }
15273
+ };
15270
15274
if (!(hasDefaultClause || (type.flags & TypeFlags.Union))) {
15271
15275
let impliedType = getTypeWithFacts(getUnionType(clauseWitnesses.map(getTypeFromName)), switchFacts);
15272
15276
if (impliedType.flags & TypeFlags.Union) {
15273
15277
impliedType = getAssignmentReducedType(impliedType as UnionType, getBaseConstraintOfType(type) || type);
15274
15278
}
15275
- if (!(impliedType.flags & TypeFlags.Never)) {
15276
- if (isTypeSubtypeOf(impliedType, type)) {
15277
- // Intersection to handle `string` being a subtype of `keyof T`
15278
- return isTypeAny ? impliedType : getIntersectionType([type, impliedType]);
15279
- }
15280
- if (type.flags & TypeFlags.Instantiable) {
15281
- const constraint = getBaseConstraintOfType(type) || anyType;
15282
- if (isTypeSubtypeOf(impliedType, constraint)) {
15283
- return getIntersectionType([type, impliedType]);
15284
- }
15279
+ if (isTypeSubtypeOf(impliedType, type)) {
15280
+ // Intersection to handle `string` being a subtype of `keyof T`
15281
+ return type.flags & TypeFlags.Any ? impliedType : getIntersectionType([type, impliedType]);
15282
+ }
15283
+ if (type.flags & TypeFlags.Instantiable) {
15284
+ const constraint = getBaseConstraintOfType(type) || anyType;
15285
+ if (isTypeSubtypeOf(impliedType, constraint)) {
15286
+ return getIntersectionType([type, impliedType]);
15285
15287
}
15286
15288
}
15287
15289
}
0 commit comments