@@ -400,6 +400,10 @@ namespace ts {
400400 let anyArrayType: Type;
401401 let autoArrayType: Type;
402402 let anyReadonlyArrayType: Type;
403+ let deferredGlobalNonNullableTypeAlias: Symbol;
404+ let deferredGlobalNonNullableTypeFallback: Type;
405+ let deferredGlobalNonNullableTypeFallbackInstantiationCache: Map<Type>;
406+ let deferredGlobalNonNullableTypeParameterFallback: TypeParameter;
403407
404408 // The library files are only loaded when the feature is used.
405409 // This allows users to just specify library files they want to used through --lib
@@ -11037,8 +11041,31 @@ namespace ts {
1103711041 return type.flags & TypeFlags.Undefined ? type : getUnionType([type, undefinedType]);
1103811042 }
1103911043
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+
1104011067 function getNonNullableType(type: Type): Type {
11041- return strictNullChecks ? getTypeWithFacts (type, TypeFacts.NEUndefinedOrNull ) : type;
11068+ return strictNullChecks ? getGlobalNonNullableTypeInstantiation (type) : type;
1104211069 }
1104311070
1104411071 /**
@@ -13314,7 +13341,6 @@ namespace ts {
1331413341 return parent.kind === SyntaxKind.PropertyAccessExpression ||
1331513342 parent.kind === SyntaxKind.CallExpression && (<CallExpression>parent).expression === node ||
1331613343 parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>parent).expression === node ||
13317- parent.kind === SyntaxKind.NonNullExpression ||
1331813344 parent.kind === SyntaxKind.BindingElement && (<BindingElement>parent).name === node && !!(<BindingElement>parent).initializer;
1331913345 }
1332013346
0 commit comments