@@ -400,6 +400,10 @@ namespace ts {
400
400
let anyArrayType: Type;
401
401
let autoArrayType: Type;
402
402
let anyReadonlyArrayType: Type;
403
+ let deferredGlobalNonNullableTypeAlias: Symbol;
404
+ let deferredGlobalNonNullableTypeFallback: Type;
405
+ let deferredGlobalNonNullableTypeFallbackInstantiationCache: Map<Type>;
406
+ let deferredGlobalNonNullableTypeParameterFallback: TypeParameter;
403
407
404
408
// The library files are only loaded when the feature is used.
405
409
// This allows users to just specify library files they want to used through --lib
@@ -11037,8 +11041,31 @@ namespace ts {
11037
11041
return type.flags & TypeFlags.Undefined ? type : getUnionType([type, undefinedType]);
11038
11042
}
11039
11043
11044
+ function getGlobalNonNullableTypeInstantiation(type: Type) {
11045
+ if (!deferredGlobalNonNullableTypeAlias) {
11046
+ deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable" as __String, SymbolFlags.TypeAlias, /*diagnostic*/ undefined) || unknownSymbol;
11047
+ }
11048
+ // Use NonNullable global type alias if available to improve quick info/declaration emit
11049
+ if (deferredGlobalNonNullableTypeAlias !== unknownSymbol) {
11050
+ return getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]);
11051
+ }
11052
+ if (!deferredGlobalNonNullableTypeFallback) {
11053
+ const p = deferredGlobalNonNullableTypeParameterFallback = createType(TypeFlags.TypeParameter) as TypeParameter;
11054
+ deferredGlobalNonNullableTypeFallback = getConditionalType(p, getUnionType([nullType, undefinedType]), neverType, p, /*inferTypeParameters*/ undefined, /*target*/ undefined, /*mapper*/ undefined, /*alias*/ undefined, /*aliasTypeArguments*/ undefined);
11055
+ deferredGlobalNonNullableTypeFallbackInstantiationCache = createMap();
11056
+ }
11057
+ // Fallback to manufacturing an anonymous conditional type instantiation
11058
+ const args = [type];
11059
+ const id = getTypeListId(args);
11060
+ let instantiation = deferredGlobalNonNullableTypeFallbackInstantiationCache.get(id);
11061
+ if (!instantiation) {
11062
+ deferredGlobalNonNullableTypeFallbackInstantiationCache.set(id, instantiation = instantiateType(deferredGlobalNonNullableTypeFallback, createTypeMapper([deferredGlobalNonNullableTypeParameterFallback], [type])));
11063
+ }
11064
+ return instantiation;
11065
+ }
11066
+
11040
11067
function getNonNullableType(type: Type): Type {
11041
- return strictNullChecks ? getTypeWithFacts (type, TypeFacts.NEUndefinedOrNull ) : type;
11068
+ return strictNullChecks ? getGlobalNonNullableTypeInstantiation (type) : type;
11042
11069
}
11043
11070
11044
11071
/**
@@ -13314,7 +13341,6 @@ namespace ts {
13314
13341
return parent.kind === SyntaxKind.PropertyAccessExpression ||
13315
13342
parent.kind === SyntaxKind.CallExpression && (<CallExpression>parent).expression === node ||
13316
13343
parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>parent).expression === node ||
13317
- parent.kind === SyntaxKind.NonNullExpression ||
13318
13344
parent.kind === SyntaxKind.BindingElement && (<BindingElement>parent).name === node && !!(<BindingElement>parent).initializer;
13319
13345
}
13320
13346
0 commit comments