Narrowing unknown by typeof object to object | null

Fixes #26327
This commit is contained in:
Sheetal Nandi
2018-08-31 15:24:53 -07:00
parent cbdfc01e25
commit f1a179a314
5 changed files with 52 additions and 0 deletions

View File

@@ -14925,6 +14925,9 @@ namespace ts {
return type;
}
if (assumeTrue && !(type.flags & TypeFlags.Union)) {
if (type.flags & TypeFlags.Unknown && literal.text === "object") {
return getUnionType([nonPrimitiveType, nullType]);
}
// We narrow a non-union type to an exact primitive type if the non-union type
// is a supertype of that primitive type. For example, type 'any' can be narrowed
// to one of the primitive types.