@@ -1226,8 +1226,11 @@ export const enum TypeFacts {
1226
1226
Falsy = 1 << 23, // !x
1227
1227
IsUndefined = 1 << 24, // Contains undefined or intersection with undefined
1228
1228
IsNull = 1 << 25, // Contains null or intersection with null
1229
+ IsPossiblyUndefined = 1 << 26, // Possibly undefined
1230
+ IsPossiblyNull = 1 << 27, // Possibly null
1229
1231
IsUndefinedOrNull = IsUndefined | IsNull,
1230
- All = (1 << 27) - 1,
1232
+ IsPossiblyUndefinedOrNull = IsPossiblyUndefined | IsPossiblyNull,
1233
+ All = (1 << 29) - 1,
1231
1234
// The following members encode facts about particular kinds of types for use in the getTypeFacts function.
1232
1235
// The presence of a particular fact means that the given test is true for some (and possibly all) values
1233
1236
// of that kind of type.
@@ -1270,11 +1273,12 @@ export const enum TypeFacts {
1270
1273
FunctionStrictFacts = TypeofEQFunction | TypeofEQHostObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy,
1271
1274
FunctionFacts = FunctionStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy,
1272
1275
VoidFacts = TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | EQUndefined | EQUndefinedOrNull | NENull | Falsy,
1273
- UndefinedFacts = TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | EQUndefined | EQUndefinedOrNull | NENull | Falsy | IsUndefined,
1274
- NullFacts = TypeofEQObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEFunction | TypeofNEHostObject | EQNull | EQUndefinedOrNull | NEUndefined | Falsy | IsNull,
1275
- EmptyObjectStrictFacts = All & ~(EQUndefined | EQNull | EQUndefinedOrNull | IsUndefinedOrNull),
1276
- EmptyObjectFacts = All & ~IsUndefinedOrNull,
1277
- UnknownFacts = All & ~IsUndefinedOrNull,
1276
+ UndefinedFacts = TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | EQUndefined | EQUndefinedOrNull | NENull | Falsy | IsUndefined | IsPossiblyUndefined,
1277
+ NullFacts = TypeofEQObject | TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEFunction | TypeofNEHostObject | EQNull | EQUndefinedOrNull | NEUndefined | Falsy | IsNull | IsPossiblyNull,
1278
+ EmptyObjectStrictFacts = All & ~(EQUndefined | EQNull | EQUndefinedOrNull | IsUndefinedOrNull | IsPossiblyUndefinedOrNull),
1279
+ EmptyObjectFacts = All & ~(IsUndefinedOrNull | IsPossiblyUndefinedOrNull),
1280
+ UnknownStrictFacts = All & ~IsUndefinedOrNull,
1281
+ UnknownFacts = All & ~(IsUndefinedOrNull | IsPossiblyUndefinedOrNull),
1278
1282
AllTypeofNE = TypeofNEString | TypeofNENumber | TypeofNEBigInt | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | NEUndefined,
1279
1283
// Masks
1280
1284
OrFactsMask = TypeofEQFunction | TypeofNEObject,
@@ -27477,7 +27481,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27477
27481
if (flags & TypeFlags.Intersection) {
27478
27482
return getIntersectionTypeFacts(type as IntersectionType, callerOnlyNeeds);
27479
27483
}
27480
- return TypeFacts.UnknownFacts;
27484
+ return strictNullChecks && flags & TypeFlags.Unknown ? TypeFacts.UnknownStrictFacts : TypeFacts.UnknownFacts;
27481
27485
}
27482
27486
27483
27487
function getIntersectionTypeFacts(type: IntersectionType, callerOnlyNeeds: TypeFacts): TypeFacts {
@@ -33699,7 +33703,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33699
33703
}
33700
33704
error(
33701
33705
node,
33702
- facts & TypeFacts.IsUndefined ? facts & TypeFacts.IsNull ?
33706
+ facts & TypeFacts.IsPossiblyUndefined ? facts & TypeFacts.IsPossiblyNull ?
33703
33707
Diagnostics._0_is_possibly_null_or_undefined :
33704
33708
Diagnostics._0_is_possibly_undefined :
33705
33709
Diagnostics._0_is_possibly_null,
@@ -33709,7 +33713,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33709
33713
else {
33710
33714
error(
33711
33715
node,
33712
- facts & TypeFacts.IsUndefined ? facts & TypeFacts.IsNull ?
33716
+ facts & TypeFacts.IsPossiblyUndefined ? facts & TypeFacts.IsPossiblyNull ?
33713
33717
Diagnostics.Object_is_possibly_null_or_undefined :
33714
33718
Diagnostics.Object_is_possibly_undefined :
33715
33719
Diagnostics.Object_is_possibly_null,
@@ -33720,7 +33724,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33720
33724
function reportCannotInvokePossiblyNullOrUndefinedError(node: Node, facts: TypeFacts) {
33721
33725
error(
33722
33726
node,
33723
- facts & TypeFacts.IsUndefined ? facts & TypeFacts.IsNull ?
33727
+ facts & TypeFacts.IsPossiblyUndefined ? facts & TypeFacts.IsPossiblyNull ?
33724
33728
Diagnostics.Cannot_invoke_an_object_which_is_possibly_null_or_undefined :
33725
33729
Diagnostics.Cannot_invoke_an_object_which_is_possibly_undefined :
33726
33730
Diagnostics.Cannot_invoke_an_object_which_is_possibly_null,
@@ -33743,8 +33747,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33743
33747
error(node, Diagnostics.Object_is_of_type_unknown);
33744
33748
return errorType;
33745
33749
}
33746
- const facts = getTypeFacts(type, TypeFacts.IsUndefinedOrNull );
33747
- if (facts & TypeFacts.IsUndefinedOrNull ) {
33750
+ const facts = getTypeFacts(type, TypeFacts.IsPossiblyUndefinedOrNull );
33751
+ if (facts & TypeFacts.IsPossiblyUndefinedOrNull ) {
33748
33752
reportError(node, facts);
33749
33753
const t = getNonNullableType(type);
33750
33754
return t.flags & (TypeFlags.Nullable | TypeFlags.Never) ? errorType : t;
0 commit comments