File tree 1 file changed +8
-5
lines changed
1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -20320,14 +20320,17 @@ namespace ts {
20320
20320
}
20321
20321
20322
20322
function getGlobalNonNullableTypeInstantiation(type: Type) {
20323
+ // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
20324
+ // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
20325
+ // that isn't eliminated by a NonNullable<T> instantiation.
20326
+ const reducedType = getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull);
20323
20327
if (!deferredGlobalNonNullableTypeAlias) {
20324
20328
deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable" as __String, SymbolFlags.TypeAlias, /*diagnostic*/ undefined) || unknownSymbol;
20325
20329
}
20326
- // Use NonNullable global type alias if available to improve quick info/declaration emit
20327
- if (deferredGlobalNonNullableTypeAlias !== unknownSymbol) {
20328
- return getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]);
20329
- }
20330
- return getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); // Type alias unavailable, fall back to non-higher-order behavior
20330
+ // If the NonNullable<T> type is available, return an instantiation. Otherwise just return the reduced type.
20331
+ return deferredGlobalNonNullableTypeAlias !== unknownSymbol ?
20332
+ getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [reducedType]) :
20333
+ reducedType;
20331
20334
}
20332
20335
20333
20336
function getNonNullableType(type: Type): Type {
You can’t perform that action at this time.
0 commit comments