@typescript-deploys/pr-build 4.8.0-pr-49119-45 → 4.8.0-pr-49233-9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-insiders.20220524";
103
+ ts.version = ts.versionMajorMinor + ".0-insiders.20220525";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -5101,11 +5101,6 @@ var ts;
5101
5101
  // Flags that require TypeFlags.Union
5102
5102
  /* @internal */
5103
5103
  ObjectFlags[ObjectFlags["ContainsIntersections"] = 16777216] = "ContainsIntersections";
5104
- /* @internal */
5105
- ObjectFlags[ObjectFlags["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
5106
- /* @internal */
5107
- ObjectFlags[ObjectFlags["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
5108
- /* @internal */
5109
5104
  // Flags that require TypeFlags.Intersection
5110
5105
  /* @internal */
5111
5106
  ObjectFlags[ObjectFlags["IsNeverIntersectionComputed"] = 16777216] = "IsNeverIntersectionComputed";
@@ -43153,16 +43148,20 @@ var ts;
43153
43148
  function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) {
43154
43149
  return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode);
43155
43150
  }
43151
+ var jsOnlyExtensions = [Extensions.JavaScript];
43152
+ var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript];
43153
+ var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false);
43154
+ var tsconfigExtensions = [Extensions.TSConfig];
43156
43155
  function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) {
43157
43156
  var containingDirectory = ts.getDirectoryPath(containingFile);
43158
43157
  // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features
43159
43158
  var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0;
43160
- return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference);
43159
+ var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions;
43160
+ if (compilerOptions.resolveJsonModule) {
43161
+ extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false);
43162
+ }
43163
+ return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference);
43161
43164
  }
43162
- var jsOnlyExtensions = [Extensions.JavaScript];
43163
- var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript];
43164
- var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false);
43165
- var tsconfigExtensions = [Extensions.TSConfig];
43166
43165
  function tryResolveJSModuleWorker(moduleName, initialDir, host) {
43167
43166
  return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined);
43168
43167
  }
@@ -48543,7 +48542,6 @@ var ts;
48543
48542
  var emptyTypeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type" /* Type */);
48544
48543
  emptyTypeLiteralSymbol.members = ts.createSymbolTable();
48545
48544
  var emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48546
- var unknownUnionType = strictNullChecks ? getUnionType([undefinedType, nullType, createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray)]) : unknownType;
48547
48545
  var emptyGenericType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48548
48546
  emptyGenericType.instantiations = new ts.Map();
48549
48547
  var anyFunctionType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
@@ -58713,7 +58711,7 @@ var ts;
58713
58711
  }
58714
58712
  }
58715
58713
  }
58716
- else if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58714
+ else if (t.flags & 469892092 /* DisjointDomains */) {
58717
58715
  hasDisjointDomainType = true;
58718
58716
  }
58719
58717
  }
@@ -58725,7 +58723,7 @@ var ts;
58725
58723
  // intersection operation to reduce the union constraints.
58726
58724
  for (var _a = 0, types_6 = types; _a < types_6.length; _a++) {
58727
58725
  var t = types_6[_a];
58728
- if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58726
+ if (t.flags & 469892092 /* DisjointDomains */) {
58729
58727
  constraints = ts.append(constraints, t);
58730
58728
  }
58731
58729
  }
@@ -61274,7 +61272,7 @@ var ts;
61274
61272
  }
61275
61273
  return includes;
61276
61274
  }
61277
- function removeRedundantSupertypes(types, includes) {
61275
+ function removeRedundantPrimitiveTypes(types, includes) {
61278
61276
  var i = types.length;
61279
61277
  while (i > 0) {
61280
61278
  i--;
@@ -61282,9 +61280,7 @@ var ts;
61282
61280
  var remove = t.flags & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61283
61281
  t.flags & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61284
61282
  t.flags & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61285
- t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61286
- t.flags & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61287
- isEmptyAnonymousObjectType(t) && includes & 470302716 /* DefinitelyNonNullable */;
61283
+ t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */;
61288
61284
  if (remove) {
61289
61285
  ts.orderedRemoveItemAt(types, i);
61290
61286
  }
@@ -61406,7 +61402,7 @@ var ts;
61406
61402
  // a type alias of the form "type List<T> = T & { next: List<T> }" cannot be reduced during its declaration.
61407
61403
  // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
61408
61404
  // for intersections of types with signatures can be deterministic.
61409
- function getIntersectionType(types, aliasSymbol, aliasTypeArguments, noSupertypeReduction) {
61405
+ function getIntersectionType(types, aliasSymbol, aliasTypeArguments) {
61410
61406
  var typeMembershipMap = new ts.Map();
61411
61407
  var includes = addTypesToIntersection(typeMembershipMap, 0, types);
61412
61408
  var typeSet = ts.arrayFrom(typeMembershipMap.values());
@@ -61443,11 +61439,11 @@ var ts;
61443
61439
  if (includes & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61444
61440
  includes & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61445
61441
  includes & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61446
- includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61447
- includes & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61448
- includes & 16777216 /* IncludesEmptyObject */ && includes & 470302716 /* DefinitelyNonNullable */) {
61449
- if (!noSupertypeReduction)
61450
- removeRedundantSupertypes(typeSet, includes);
61442
+ includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */) {
61443
+ removeRedundantPrimitiveTypes(typeSet, includes);
61444
+ }
61445
+ if (includes & 16777216 /* IncludesEmptyObject */ && includes & 524288 /* Object */) {
61446
+ ts.orderedRemoveItemAt(typeSet, ts.findIndex(typeSet, isEmptyAnonymousObjectType));
61451
61447
  }
61452
61448
  if (includes & 262144 /* IncludesMissingType */) {
61453
61449
  typeSet[typeSet.indexOf(undefinedType)] = missingType;
@@ -61486,9 +61482,8 @@ var ts;
61486
61482
  }
61487
61483
  var constituents = getCrossProductIntersections(typeSet);
61488
61484
  // We attach a denormalized origin type when at least one constituent of the cross-product union is an
61489
- // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions) and
61490
- // the denormalized origin has fewer constituents than the union itself.
61491
- var origin = ts.some(constituents, function (t) { return !!(t.flags & 2097152 /* Intersection */); }) && getConstituentCountOfTypes(constituents) > getConstituentCountOfTypes(typeSet) ? createOriginUnionOrIntersectionType(2097152 /* Intersection */, typeSet) : undefined;
61485
+ // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions).
61486
+ var origin = ts.some(constituents, function (t) { return !!(t.flags & 2097152 /* Intersection */); }) ? createOriginUnionOrIntersectionType(2097152 /* Intersection */, typeSet) : undefined;
61492
61487
  result = getUnionType(constituents, 1 /* Literal */, aliasSymbol, aliasTypeArguments, origin);
61493
61488
  }
61494
61489
  }
@@ -61531,21 +61526,11 @@ var ts;
61531
61526
  }
61532
61527
  return intersections;
61533
61528
  }
61534
- function getConstituentCount(type) {
61535
- return !(type.flags & 3145728 /* UnionOrIntersection */) || type.aliasSymbol ? 1 :
61536
- type.flags & 1048576 /* Union */ && type.origin ? getConstituentCount(type.origin) :
61537
- getConstituentCountOfTypes(type.types);
61538
- }
61539
- function getConstituentCountOfTypes(types) {
61540
- return ts.reduceLeft(types, function (n, t) { return n + getConstituentCount(t); }, 0);
61541
- }
61542
61529
  function getTypeFromIntersectionTypeNode(node) {
61543
61530
  var links = getNodeLinks(node);
61544
61531
  if (!links.resolvedType) {
61545
61532
  var aliasSymbol = getAliasSymbolForTypeNode(node);
61546
- var types = ts.map(node.types, getTypeFromTypeNode);
61547
- var noSupertypeReduction = types.length === 2 && !!(types[0].flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) && types[1] === emptyTypeLiteralType;
61548
- links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction);
61533
+ links.resolvedType = getIntersectionType(ts.map(node.types, getTypeFromTypeNode), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
61549
61534
  }
61550
61535
  return links.resolvedType;
61551
61536
  }
@@ -64331,17 +64316,6 @@ var ts;
64331
64316
  return !!(ts.getObjectFlags(type) & 16 /* Anonymous */ && (type.members && isEmptyResolvedType(type) ||
64332
64317
  type.symbol && type.symbol.flags & 2048 /* TypeLiteral */ && getMembersOfSymbol(type.symbol).size === 0));
64333
64318
  }
64334
- function isUnknownLikeUnionType(type) {
64335
- if (strictNullChecks && type.flags & 1048576 /* Union */) {
64336
- if (!(type.objectFlags & 33554432 /* IsUnknownLikeUnionComputed */)) {
64337
- var types = type.types;
64338
- type.objectFlags |= 33554432 /* IsUnknownLikeUnionComputed */ | (types.length >= 3 && types[0].flags & 32768 /* Undefined */ &&
64339
- types[1].flags & 65536 /* Null */ && ts.some(types, isEmptyAnonymousObjectType) ? 67108864 /* IsUnknownLikeUnion */ : 0);
64340
- }
64341
- return !!(type.objectFlags & 67108864 /* IsUnknownLikeUnion */);
64342
- }
64343
- return false;
64344
- }
64345
64319
  function isStringIndexSignatureOnlyType(type) {
64346
64320
  return type.flags & 524288 /* Object */ && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfosOfType(type).length === 1 && !!getIndexInfoOfType(type, stringType) ||
64347
64321
  type.flags & 3145728 /* UnionOrIntersection */ && ts.every(type.types, isStringIndexSignatureOnlyType) ||
@@ -64421,7 +64395,7 @@ var ts;
64421
64395
  return true;
64422
64396
  if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
64423
64397
  return true;
64424
- if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */ && !(relation === strictSubtypeRelation && isEmptyAnonymousObjectType(source)))
64398
+ if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
64425
64399
  return true;
64426
64400
  if (relation === assignableRelation || relation === comparableRelation) {
64427
64401
  if (s & 1 /* Any */)
@@ -64431,9 +64405,6 @@ var ts;
64431
64405
  // bit-flag enum types sometimes look like literal enum types with numeric literal values.
64432
64406
  if (s & (8 /* Number */ | 256 /* NumberLiteral */) && !(s & 1024 /* EnumLiteral */) && (t & 32 /* Enum */ || relation === assignableRelation && t & 256 /* NumberLiteral */ && t & 1024 /* EnumLiteral */))
64433
64407
  return true;
64434
- // Anything is assignable to a union containing undefined, null, and {}
64435
- if (isUnknownLikeUnionType(target))
64436
- return true;
64437
64408
  }
64438
64409
  return false;
64439
64410
  }
@@ -64476,27 +64447,16 @@ var ts;
64476
64447
  function getNormalizedType(type, writing) {
64477
64448
  while (true) {
64478
64449
  var t = isFreshLiteralType(type) ? type.regularType :
64479
- ts.getObjectFlags(type) & 4 /* Reference */ ? type.node ? createTypeReference(type.target, getTypeArguments(type)) : getSingleBaseForNonAugmentingSubtype(type) || type :
64480
- type.flags & 3145728 /* UnionOrIntersection */ ? getNormalizedUnionOrIntersectionType(type, writing) :
64450
+ ts.getObjectFlags(type) & 4 /* Reference */ && type.node ? createTypeReference(type.target, getTypeArguments(type)) :
64451
+ type.flags & 3145728 /* UnionOrIntersection */ ? getReducedType(type) :
64481
64452
  type.flags & 33554432 /* Substitution */ ? writing ? type.baseType : type.substitute :
64482
64453
  type.flags & 25165824 /* Simplifiable */ ? getSimplifiedType(type, writing) :
64483
64454
  type;
64455
+ t = getSingleBaseForNonAugmentingSubtype(t) || t;
64484
64456
  if (t === type)
64485
- return t;
64457
+ break;
64486
64458
  type = t;
64487
64459
  }
64488
- }
64489
- function getNormalizedUnionOrIntersectionType(type, writing) {
64490
- var reduced = getReducedType(type);
64491
- if (reduced !== type) {
64492
- return reduced;
64493
- }
64494
- if (type.flags & 2097152 /* Intersection */) {
64495
- var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); });
64496
- if (normalizedTypes !== type.types) {
64497
- return getIntersectionType(normalizedTypes);
64498
- }
64499
- }
64500
64460
  return type;
64501
64461
  }
64502
64462
  /**
@@ -67495,22 +67455,20 @@ var ts;
67495
67455
  return type.flags & 32768 /* Undefined */ ? type : getUnionType([type, isProperty ? missingType : undefinedType]);
67496
67456
  }
67497
67457
  function getGlobalNonNullableTypeInstantiation(type) {
67458
+ // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67459
+ // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67460
+ // that isn't eliminated by a NonNullable<T> instantiation.
67461
+ var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67498
67462
  if (!deferredGlobalNonNullableTypeAlias) {
67499
67463
  deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable", 524288 /* TypeAlias */, /*diagnostic*/ undefined) || unknownSymbol;
67500
67464
  }
67465
+ // If the NonNullable<T> type is available, return an instantiation. Otherwise just return the reduced type.
67501
67466
  return deferredGlobalNonNullableTypeAlias !== unknownSymbol ?
67502
- getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]) :
67503
- getIntersectionType([type, emptyObjectType]);
67467
+ getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [reducedType]) :
67468
+ reducedType;
67504
67469
  }
67505
67470
  function getNonNullableType(type) {
67506
- if (strictNullChecks) {
67507
- // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67508
- // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67509
- // that isn't eliminated by a NonNullable<T> instantiation.
67510
- var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67511
- return maybeTypeOfKind(reducedType, 465829888 /* Instantiable */) ? getGlobalNonNullableTypeInstantiation(reducedType) : reducedType;
67512
- }
67513
- return type;
67471
+ return strictNullChecks ? getGlobalNonNullableTypeInstantiation(type) : type;
67514
67472
  }
67515
67473
  function addOptionalTypeMarker(type) {
67516
67474
  return strictNullChecks ? getUnionType([type, optionalType]) : type;
@@ -69541,24 +69499,6 @@ var ts;
69541
69499
  function getTypeWithFacts(type, include) {
69542
69500
  return filterType(type, function (t) { return (getTypeFacts(t) & include) !== 0; });
69543
69501
  }
69544
- function getIntersectionWithFacts(type, facts) {
69545
- var reduced = recombineUnknownType(getTypeWithFacts(strictNullChecks && type.flags & 2 /* Unknown */ ? unknownUnionType : type, facts));
69546
- if (strictNullChecks) {
69547
- switch (facts) {
69548
- case 524288 /* NEUndefined */:
69549
- return mapType(reduced, function (t) { return getTypeFacts(t) & 65536 /* EQUndefined */ ? getIntersectionType([t, getTypeFacts(t) & 131072 /* EQNull */ && !maybeTypeOfKind(reduced, 65536 /* Null */) ? getUnionType([emptyObjectType, nullType]) : emptyObjectType]) : t; });
69550
- case 1048576 /* NENull */:
69551
- return mapType(reduced, function (t) { return getTypeFacts(t) & 131072 /* EQNull */ ? getIntersectionType([t, getTypeFacts(t) & 65536 /* EQUndefined */ && !maybeTypeOfKind(reduced, 32768 /* Undefined */) ? getUnionType([emptyObjectType, undefinedType]) : emptyObjectType]) : t; });
69552
- case 2097152 /* NEUndefinedOrNull */:
69553
- case 4194304 /* Truthy */:
69554
- return mapType(reduced, function (t) { return getTypeFacts(t) & 262144 /* EQUndefinedOrNull */ ? getGlobalNonNullableTypeInstantiation(t) : t; });
69555
- }
69556
- }
69557
- return reduced;
69558
- }
69559
- function recombineUnknownType(type) {
69560
- return type === unknownUnionType ? unknownType : type;
69561
- }
69562
69502
  function getTypeWithDefault(type, defaultExpression) {
69563
69503
  return defaultExpression ?
69564
69504
  getUnionType([getNonUndefinedType(type), getTypeOfExpression(defaultExpression)]) :
@@ -70616,7 +70556,7 @@ var ts;
70616
70556
  if (isEvolvingArrayTypeList(types)) {
70617
70557
  return getEvolvingArrayType(getUnionType(ts.map(types, getElementTypeOfEvolvingArrayType)));
70618
70558
  }
70619
- var result = recombineUnknownType(getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction));
70559
+ var result = getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction);
70620
70560
  if (result !== declaredType && result.flags & declaredType.flags & 1048576 /* Union */ && ts.arraysEqual(result.types, declaredType.types)) {
70621
70561
  return declaredType;
70622
70562
  }
@@ -70718,7 +70658,8 @@ var ts;
70718
70658
  }
70719
70659
  function narrowTypeByTruthiness(type, expr, assumeTrue) {
70720
70660
  if (isMatchingReference(reference, expr)) {
70721
- return getIntersectionWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70661
+ return type.flags & 2 /* Unknown */ && assumeTrue ? nonNullUnknownType :
70662
+ getTypeWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70722
70663
  }
70723
70664
  if (strictNullChecks && assumeTrue && optionalChainContainsReference(expr, reference)) {
70724
70665
  type = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
@@ -70871,6 +70812,9 @@ var ts;
70871
70812
  assumeTrue = !assumeTrue;
70872
70813
  }
70873
70814
  var valueType = getTypeOfExpression(value);
70815
+ if (assumeTrue && (type.flags & 2 /* Unknown */) && (operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */) && (valueType.flags & 65536 /* Null */)) {
70816
+ return getUnionType([nullType, undefinedType]);
70817
+ }
70874
70818
  if ((type.flags & 2 /* Unknown */) && assumeTrue && (operator === 36 /* EqualsEqualsEqualsToken */ || operator === 37 /* ExclamationEqualsEqualsToken */)) {
70875
70819
  if (valueType.flags & (131068 /* Primitive */ | 67108864 /* NonPrimitive */)) {
70876
70820
  return valueType;
@@ -70890,7 +70834,7 @@ var ts;
70890
70834
  valueType.flags & 65536 /* Null */ ?
70891
70835
  assumeTrue ? 131072 /* EQNull */ : 1048576 /* NENull */ :
70892
70836
  assumeTrue ? 65536 /* EQUndefined */ : 524288 /* NEUndefined */;
70893
- return getIntersectionWithFacts(type, facts);
70837
+ return type.flags & 2 /* Unknown */ && facts & (1048576 /* NENull */ | 2097152 /* NEUndefinedOrNull */) ? nonNullUnknownType : getTypeWithFacts(type, facts);
70894
70838
  }
70895
70839
  if (assumeTrue) {
70896
70840
  var filterFn = operator === 34 /* EqualsEqualsToken */ ?
@@ -70918,11 +70862,17 @@ var ts;
70918
70862
  if (type.flags & 1 /* Any */ && literal.text === "function") {
70919
70863
  return type;
70920
70864
  }
70865
+ if (assumeTrue && type.flags & 2 /* Unknown */ && literal.text === "object") {
70866
+ // The non-null unknown type is used to track whether a previous narrowing operation has removed the null type
70867
+ // from the unknown type. For example, the expression `x && typeof x === 'object'` first narrows x to the non-null
70868
+ // unknown type, and then narrows that to the non-primitive type.
70869
+ return type === nonNullUnknownType ? nonPrimitiveType : getUnionType([nonPrimitiveType, nullType]);
70870
+ }
70921
70871
  var facts = assumeTrue ?
70922
70872
  typeofEQFacts.get(literal.text) || 128 /* TypeofEQHostObject */ :
70923
70873
  typeofNEFacts.get(literal.text) || 32768 /* TypeofNEHostObject */;
70924
70874
  var impliedType = getImpliedTypeFromTypeofGuard(type, literal.text);
70925
- return getTypeWithFacts(assumeTrue && impliedType ? narrowTypeByImpliedType(type, impliedType) : type, facts);
70875
+ return getTypeWithFacts(assumeTrue && impliedType ? mapType(type, narrowUnionMemberByTypeof(impliedType)) : type, facts);
70926
70876
  }
70927
70877
  function narrowTypeBySwitchOptionalChainContainment(type, switchStatement, clauseStart, clauseEnd, clauseCheck) {
70928
70878
  var everyClauseChecks = clauseStart !== clauseEnd && ts.every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), clauseCheck);
@@ -70971,10 +70921,10 @@ var ts;
70971
70921
  }
70972
70922
  function getImpliedTypeFromTypeofGuard(type, text) {
70973
70923
  switch (text) {
70974
- case "object":
70975
- return type.flags & 1 /* Any */ ? type : getUnionType([nullType, nonPrimitiveType]);
70976
70924
  case "function":
70977
70925
  return type.flags & 1 /* Any */ ? type : globalFunctionType;
70926
+ case "object":
70927
+ return type.flags & 2 /* Unknown */ ? getUnionType([nonPrimitiveType, nullType]) : type;
70978
70928
  default:
70979
70929
  return typeofTypesByName.get(text);
70980
70930
  }
@@ -70985,27 +70935,22 @@ var ts;
70985
70935
  // the guard. For example: narrowing `{} | undefined` by `"boolean"` should produce the type `boolean`, not
70986
70936
  // the filtered type `{}`. For this reason we narrow constituents of the union individually, in addition to
70987
70937
  // filtering by type-facts.
70988
- function narrowTypeByImpliedType(type, candidate) {
70989
- if (type.flags & 3 /* AnyOrUnknown */) {
70990
- return candidate;
70991
- }
70992
- return mapType(type, function (t) {
70993
- if (isTypeRelatedTo(t, candidate, strictSubtypeRelation)) {
70994
- return t;
70938
+ function narrowUnionMemberByTypeof(candidate) {
70939
+ return function (type) {
70940
+ if (isTypeSubtypeOf(type, candidate)) {
70941
+ return type;
70995
70942
  }
70996
- return mapType(candidate, function (c) {
70997
- if (!areTypesComparable(t, c)) {
70998
- return neverType;
70999
- }
71000
- if (c.flags & 131068 /* Primitive */ && t.flags & 524288 /* Object */ && !isEmptyAnonymousObjectType(t)) {
71001
- return isTypeSubtypeOf(c, t) ? c : neverType;
71002
- }
71003
- if (c === globalFunctionType && isTypeSubtypeOf(c, t)) {
71004
- return c;
70943
+ if (isTypeSubtypeOf(candidate, type)) {
70944
+ return candidate;
70945
+ }
70946
+ if (type.flags & 465829888 /* Instantiable */) {
70947
+ var constraint = getBaseConstraintOfType(type) || anyType;
70948
+ if (isTypeSubtypeOf(candidate, constraint)) {
70949
+ return getIntersectionType([type, candidate]);
71005
70950
  }
71006
- return getIntersectionType([t, c]);
71007
- });
71008
- });
70951
+ }
70952
+ return type;
70953
+ };
71009
70954
  }
71010
70955
  function narrowBySwitchOnTypeOf(type, switchStatement, clauseStart, clauseEnd) {
71011
70956
  var switchWitnesses = getSwitchClauseTypeOfWitnesses(switchStatement, /*retainDefault*/ true);
@@ -71064,7 +71009,7 @@ var ts;
71064
71009
  because it is caught in the first clause.
71065
71010
  */
71066
71011
  var impliedType = getTypeWithFacts(getUnionType(clauseWitnesses.map(function (text) { return getImpliedTypeFromTypeofGuard(type, text) || type; })), switchFacts);
71067
- return getTypeWithFacts(narrowTypeByImpliedType(type, impliedType), switchFacts);
71012
+ return getTypeWithFacts(mapType(type, narrowUnionMemberByTypeof(impliedType)), switchFacts);
71068
71013
  }
71069
71014
  function isMatchingConstructorReference(expr) {
71070
71015
  return (ts.isPropertyAccessExpression(expr) && ts.idText(expr.name) === "constructor" ||
@@ -71368,9 +71313,7 @@ var ts;
71368
71313
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
71369
71314
  }
71370
71315
  function isGenericTypeWithUnionConstraint(type) {
71371
- return type.flags & 2097152 /* Intersection */ ?
71372
- ts.some(type.types, isGenericTypeWithUnionConstraint) :
71373
- !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71316
+ return !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71374
71317
  }
71375
71318
  function isGenericTypeWithoutNullableConstraint(type) {
71376
71319
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
@@ -71398,7 +71341,7 @@ var ts;
71398
71341
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
71399
71342
  someType(type, isGenericTypeWithUnionConstraint) &&
71400
71343
  (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
71401
- return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
71344
+ return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ ? getBaseConstraintOrType(t) : t; }) : type;
71402
71345
  }
71403
71346
  function isExportOrExportExpression(location) {
71404
71347
  return !!ts.findAncestor(location, function (n) {