diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6f5a3e67d0a..0a5525edaaf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6479,6 +6479,10 @@ namespace ts { assumeTrue = !assumeTrue; } const typeInfo = primitiveTypeInfo[right.text]; + // Don't narrow `undefined` + if (typeInfo && typeInfo.type === undefinedType) { + return type; + } // If the type to be narrowed is any and we're checking a primitive with assumeTrue=true, return the primitive if (!!(type.flags & TypeFlags.Any) && typeInfo && assumeTrue) { return typeInfo.type;