mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
* Cherry-pick PR #44219 into release-4.3 Component commits:4475012558Improve getNonNullableType function86f09ae87cAdd testsd45806a984More closely match previous behavior634b01ab3aAdd non-strict mode test * Update LKG Co-authored-by: Anders Hejlsberg <andersh@microsoft.com> Co-authored-by: typescript-bot <typescript@microsoft.com>
This commit is contained in:
co-authored by
Anders Hejlsberg
typescript-bot
parent
d6e6fa728e
commit
28e3e6ff2f
@@ -20239,14 +20239,17 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getGlobalNonNullableTypeInstantiation(type: Type) {
|
||||
// First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
|
||||
// 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
|
||||
// that isn't eliminated by a NonNullable<T> instantiation.
|
||||
const reducedType = getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull);
|
||||
if (!deferredGlobalNonNullableTypeAlias) {
|
||||
deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable" as __String, SymbolFlags.TypeAlias, /*diagnostic*/ undefined) || unknownSymbol;
|
||||
}
|
||||
// Use NonNullable global type alias if available to improve quick info/declaration emit
|
||||
if (deferredGlobalNonNullableTypeAlias !== unknownSymbol) {
|
||||
return getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]);
|
||||
}
|
||||
return getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); // Type alias unavailable, fall back to non-higher-order behavior
|
||||
// If the NonNullable<T> type is available, return an instantiation. Otherwise just return the reduced type.
|
||||
return deferredGlobalNonNullableTypeAlias !== unknownSymbol ?
|
||||
getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [reducedType]) :
|
||||
reducedType;
|
||||
}
|
||||
|
||||
function getNonNullableType(type: Type): Type {
|
||||
@@ -24035,7 +24038,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isGenericTypeWithUnionConstraint(type: Type) {
|
||||
return !!(type.flags & TypeFlags.Instantiable && getBaseConstraintOrType(type).flags & TypeFlags.Union);
|
||||
return !!(type.flags & TypeFlags.Instantiable && getBaseConstraintOrType(type).flags & (TypeFlags.Nullable | TypeFlags.Union));
|
||||
}
|
||||
|
||||
function containsGenericType(type: Type): boolean {
|
||||
|
||||
Reference in New Issue
Block a user