typescript 4.8.0-dev.20220526 → 4.8.0-dev.20220529

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-dev.20220526";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220529";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -5101,6 +5101,11 @@ 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 */
5104
5109
  // Flags that require TypeFlags.Intersection
5105
5110
  /* @internal */
5106
5111
  ObjectFlags[ObjectFlags["IsNeverIntersectionComputed"] = 16777216] = "IsNeverIntersectionComputed";
@@ -8414,6 +8419,7 @@ var ts;
8414
8419
  Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1: diag(2205, ts.DiagnosticCategory.Error, "Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1_2205", "Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
8415
8420
  The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement: diag(2206, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement_2206", "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement."),
8416
8421
  The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement: diag(2207, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement_2207", "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement."),
8422
+ This_type_parameter_probably_needs_an_extends_object_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_probably_needs_an_extends_object_constraint_2208", "This type parameter probably needs an `extends object` constraint."),
8417
8423
  The_project_root_is_ambiguous_but_is_required_to_resolve_export_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate: diag(2209, ts.DiagnosticCategory.Error, "The_project_root_is_ambiguous_but_is_required_to_resolve_export_map_entry_0_in_file_1_Supply_the_roo_2209", "The project root is ambiguous, but is required to resolve export map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate."),
8418
8424
  The_project_root_is_ambiguous_but_is_required_to_resolve_import_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate: diag(2210, ts.DiagnosticCategory.Error, "The_project_root_is_ambiguous_but_is_required_to_resolve_import_map_entry_0_in_file_1_Supply_the_roo_2210", "The project root is ambiguous, but is required to resolve import map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate."),
8419
8425
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
@@ -16218,9 +16224,6 @@ var ts;
16218
16224
  }
16219
16225
  ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire;
16220
16226
  function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
16221
- if (node.kind === 203 /* BindingElement */) {
16222
- node = node.parent.parent;
16223
- }
16224
16227
  return ts.isVariableDeclaration(node) &&
16225
16228
  !!node.initializer &&
16226
16229
  isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true);
@@ -20032,8 +20035,9 @@ var ts;
20032
20035
  */
20033
20036
  function isFileForcedToBeModuleByFormat(file) {
20034
20037
  // Excludes declaration files - they still require an explicit `export {}` or the like
20035
- // for back compat purposes.
20036
- return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined;
20038
+ // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
20039
+ // that aren't esm-mode (meaning not in a `type: module` scope).
20040
+ return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) && !file.isDeclarationFile ? true : undefined;
20037
20041
  }
20038
20042
  function getSetExternalModuleIndicator(options) {
20039
20043
  // TODO: Should this callback be cached?
@@ -20041,7 +20045,7 @@ var ts;
20041
20045
  case ts.ModuleDetectionKind.Force:
20042
20046
  // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule
20043
20047
  return function (file) {
20044
- file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file);
20048
+ file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined;
20045
20049
  };
20046
20050
  case ts.ModuleDetectionKind.Legacy:
20047
20051
  // Files are modules if they have imports, exports, or import.meta
@@ -20101,7 +20105,8 @@ var ts;
20101
20105
  }
20102
20106
  ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind;
20103
20107
  function getEmitModuleDetectionKind(options) {
20104
- return options.moduleDetection || ts.ModuleDetectionKind.Auto;
20108
+ return options.moduleDetection ||
20109
+ (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto);
20105
20110
  }
20106
20111
  ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind;
20107
20112
  function hasJsonModuleEmitEnabled(options) {
@@ -46946,12 +46951,14 @@ var ts;
46946
46951
  }
46947
46952
  }
46948
46953
  function setCommonJsModuleIndicator(node) {
46949
- if (file.externalModuleIndicator) {
46954
+ if (file.externalModuleIndicator && file.externalModuleIndicator !== true) {
46950
46955
  return false;
46951
46956
  }
46952
46957
  if (!file.commonJsModuleIndicator) {
46953
46958
  file.commonJsModuleIndicator = node;
46954
- bindSourceFileAsExternalModule();
46959
+ if (!file.externalModuleIndicator) {
46960
+ bindSourceFileAsExternalModule();
46961
+ }
46955
46962
  }
46956
46963
  return true;
46957
46964
  }
@@ -47365,7 +47372,11 @@ var ts;
47365
47372
  checkStrictModeEvalOrArguments(node, node.name);
47366
47373
  }
47367
47374
  if (!ts.isBindingPattern(node.name)) {
47368
- if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
47375
+ var possibleVariableDecl = node.kind === 254 /* VariableDeclaration */ ? node : node.parent.parent;
47376
+ if (ts.isInJSFile(node) &&
47377
+ ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) &&
47378
+ !ts.getJSDocTypeTag(node) &&
47379
+ !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
47369
47380
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
47370
47381
  }
47371
47382
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -48542,6 +48553,7 @@ var ts;
48542
48553
  var emptyTypeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type" /* Type */);
48543
48554
  emptyTypeLiteralSymbol.members = ts.createSymbolTable();
48544
48555
  var emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48556
+ var unknownUnionType = strictNullChecks ? getUnionType([undefinedType, nullType, createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray)]) : unknownType;
48545
48557
  var emptyGenericType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48546
48558
  emptyGenericType.instantiations = new ts.Map();
48547
48559
  var anyFunctionType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
@@ -50192,7 +50204,8 @@ var ts;
50192
50204
  && isAliasableOrJsExpression(node.parent.right)
50193
50205
  || node.kind === 297 /* ShorthandPropertyAssignment */
50194
50206
  || node.kind === 296 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
50195
- || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
50207
+ || node.kind === 254 /* VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)
50208
+ || node.kind === 203 /* BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent);
50196
50209
  }
50197
50210
  function isAliasableOrJsExpression(e) {
50198
50211
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50285,7 +50298,7 @@ var ts;
50285
50298
  return hasExportAssignmentSymbol(moduleSymbol);
50286
50299
  }
50287
50300
  // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker
50288
- return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias);
50301
+ return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias);
50289
50302
  }
50290
50303
  function getTargetOfImportClause(node, dontResolveAlias) {
50291
50304
  var _a;
@@ -58711,7 +58724,7 @@ var ts;
58711
58724
  }
58712
58725
  }
58713
58726
  }
58714
- else if (t.flags & 469892092 /* DisjointDomains */) {
58727
+ else if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58715
58728
  hasDisjointDomainType = true;
58716
58729
  }
58717
58730
  }
@@ -58723,7 +58736,7 @@ var ts;
58723
58736
  // intersection operation to reduce the union constraints.
58724
58737
  for (var _a = 0, types_6 = types; _a < types_6.length; _a++) {
58725
58738
  var t = types_6[_a];
58726
- if (t.flags & 469892092 /* DisjointDomains */) {
58739
+ if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58727
58740
  constraints = ts.append(constraints, t);
58728
58741
  }
58729
58742
  }
@@ -61272,7 +61285,7 @@ var ts;
61272
61285
  }
61273
61286
  return includes;
61274
61287
  }
61275
- function removeRedundantPrimitiveTypes(types, includes) {
61288
+ function removeRedundantSupertypes(types, includes) {
61276
61289
  var i = types.length;
61277
61290
  while (i > 0) {
61278
61291
  i--;
@@ -61280,7 +61293,9 @@ var ts;
61280
61293
  var remove = t.flags & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61281
61294
  t.flags & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61282
61295
  t.flags & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61283
- t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */;
61296
+ t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61297
+ t.flags & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61298
+ isEmptyAnonymousObjectType(t) && includes & 470302716 /* DefinitelyNonNullable */;
61284
61299
  if (remove) {
61285
61300
  ts.orderedRemoveItemAt(types, i);
61286
61301
  }
@@ -61402,7 +61417,7 @@ var ts;
61402
61417
  // a type alias of the form "type List<T> = T & { next: List<T> }" cannot be reduced during its declaration.
61403
61418
  // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
61404
61419
  // for intersections of types with signatures can be deterministic.
61405
- function getIntersectionType(types, aliasSymbol, aliasTypeArguments) {
61420
+ function getIntersectionType(types, aliasSymbol, aliasTypeArguments, noSupertypeReduction) {
61406
61421
  var typeMembershipMap = new ts.Map();
61407
61422
  var includes = addTypesToIntersection(typeMembershipMap, 0, types);
61408
61423
  var typeSet = ts.arrayFrom(typeMembershipMap.values());
@@ -61439,11 +61454,11 @@ var ts;
61439
61454
  if (includes & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61440
61455
  includes & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61441
61456
  includes & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
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));
61457
+ includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61458
+ includes & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61459
+ includes & 16777216 /* IncludesEmptyObject */ && includes & 470302716 /* DefinitelyNonNullable */) {
61460
+ if (!noSupertypeReduction)
61461
+ removeRedundantSupertypes(typeSet, includes);
61447
61462
  }
61448
61463
  if (includes & 262144 /* IncludesMissingType */) {
61449
61464
  typeSet[typeSet.indexOf(undefinedType)] = missingType;
@@ -61482,8 +61497,9 @@ var ts;
61482
61497
  }
61483
61498
  var constituents = getCrossProductIntersections(typeSet);
61484
61499
  // We attach a denormalized origin type when at least one constituent of the cross-product union is an
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;
61500
+ // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions) and
61501
+ // the denormalized origin has fewer constituents than the union itself.
61502
+ var origin = ts.some(constituents, function (t) { return !!(t.flags & 2097152 /* Intersection */); }) && getConstituentCountOfTypes(constituents) > getConstituentCountOfTypes(typeSet) ? createOriginUnionOrIntersectionType(2097152 /* Intersection */, typeSet) : undefined;
61487
61503
  result = getUnionType(constituents, 1 /* Literal */, aliasSymbol, aliasTypeArguments, origin);
61488
61504
  }
61489
61505
  }
@@ -61526,11 +61542,21 @@ var ts;
61526
61542
  }
61527
61543
  return intersections;
61528
61544
  }
61545
+ function getConstituentCount(type) {
61546
+ return !(type.flags & 3145728 /* UnionOrIntersection */) || type.aliasSymbol ? 1 :
61547
+ type.flags & 1048576 /* Union */ && type.origin ? getConstituentCount(type.origin) :
61548
+ getConstituentCountOfTypes(type.types);
61549
+ }
61550
+ function getConstituentCountOfTypes(types) {
61551
+ return ts.reduceLeft(types, function (n, t) { return n + getConstituentCount(t); }, 0);
61552
+ }
61529
61553
  function getTypeFromIntersectionTypeNode(node) {
61530
61554
  var links = getNodeLinks(node);
61531
61555
  if (!links.resolvedType) {
61532
61556
  var aliasSymbol = getAliasSymbolForTypeNode(node);
61533
- links.resolvedType = getIntersectionType(ts.map(node.types, getTypeFromTypeNode), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
61557
+ var types = ts.map(node.types, getTypeFromTypeNode);
61558
+ var noSupertypeReduction = types.length === 2 && !!(types[0].flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) && types[1] === emptyTypeLiteralType;
61559
+ links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction);
61534
61560
  }
61535
61561
  return links.resolvedType;
61536
61562
  }
@@ -64316,6 +64342,17 @@ var ts;
64316
64342
  return !!(ts.getObjectFlags(type) & 16 /* Anonymous */ && (type.members && isEmptyResolvedType(type) ||
64317
64343
  type.symbol && type.symbol.flags & 2048 /* TypeLiteral */ && getMembersOfSymbol(type.symbol).size === 0));
64318
64344
  }
64345
+ function isUnknownLikeUnionType(type) {
64346
+ if (strictNullChecks && type.flags & 1048576 /* Union */) {
64347
+ if (!(type.objectFlags & 33554432 /* IsUnknownLikeUnionComputed */)) {
64348
+ var types = type.types;
64349
+ type.objectFlags |= 33554432 /* IsUnknownLikeUnionComputed */ | (types.length >= 3 && types[0].flags & 32768 /* Undefined */ &&
64350
+ types[1].flags & 65536 /* Null */ && ts.some(types, isEmptyAnonymousObjectType) ? 67108864 /* IsUnknownLikeUnion */ : 0);
64351
+ }
64352
+ return !!(type.objectFlags & 67108864 /* IsUnknownLikeUnion */);
64353
+ }
64354
+ return false;
64355
+ }
64319
64356
  function isStringIndexSignatureOnlyType(type) {
64320
64357
  return type.flags & 524288 /* Object */ && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfosOfType(type).length === 1 && !!getIndexInfoOfType(type, stringType) ||
64321
64358
  type.flags & 3145728 /* UnionOrIntersection */ && ts.every(type.types, isStringIndexSignatureOnlyType) ||
@@ -64395,7 +64432,7 @@ var ts;
64395
64432
  return true;
64396
64433
  if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
64397
64434
  return true;
64398
- if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
64435
+ if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */ && !(relation === strictSubtypeRelation && isEmptyAnonymousObjectType(source)))
64399
64436
  return true;
64400
64437
  if (relation === assignableRelation || relation === comparableRelation) {
64401
64438
  if (s & 1 /* Any */)
@@ -64405,6 +64442,9 @@ var ts;
64405
64442
  // bit-flag enum types sometimes look like literal enum types with numeric literal values.
64406
64443
  if (s & (8 /* Number */ | 256 /* NumberLiteral */) && !(s & 1024 /* EnumLiteral */) && (t & 32 /* Enum */ || relation === assignableRelation && t & 256 /* NumberLiteral */ && t & 1024 /* EnumLiteral */))
64407
64444
  return true;
64445
+ // Anything is assignable to a union containing undefined, null, and {}
64446
+ if (isUnknownLikeUnionType(target))
64447
+ return true;
64408
64448
  }
64409
64449
  return false;
64410
64450
  }
@@ -64447,16 +64487,27 @@ var ts;
64447
64487
  function getNormalizedType(type, writing) {
64448
64488
  while (true) {
64449
64489
  var t = isFreshLiteralType(type) ? type.regularType :
64450
- ts.getObjectFlags(type) & 4 /* Reference */ && type.node ? createTypeReference(type.target, getTypeArguments(type)) :
64451
- type.flags & 3145728 /* UnionOrIntersection */ ? getReducedType(type) :
64490
+ ts.getObjectFlags(type) & 4 /* Reference */ ? type.node ? createTypeReference(type.target, getTypeArguments(type)) : getSingleBaseForNonAugmentingSubtype(type) || type :
64491
+ type.flags & 3145728 /* UnionOrIntersection */ ? getNormalizedUnionOrIntersectionType(type, writing) :
64452
64492
  type.flags & 33554432 /* Substitution */ ? writing ? type.baseType : type.substitute :
64453
64493
  type.flags & 25165824 /* Simplifiable */ ? getSimplifiedType(type, writing) :
64454
64494
  type;
64455
- t = getSingleBaseForNonAugmentingSubtype(t) || t;
64456
64495
  if (t === type)
64457
- break;
64496
+ return t;
64458
64497
  type = t;
64459
64498
  }
64499
+ }
64500
+ function getNormalizedUnionOrIntersectionType(type, writing) {
64501
+ var reduced = getReducedType(type);
64502
+ if (reduced !== type) {
64503
+ return reduced;
64504
+ }
64505
+ if (type.flags & 2097152 /* Intersection */) {
64506
+ var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); });
64507
+ if (normalizedTypes !== type.types) {
64508
+ return getIntersectionType(normalizedTypes);
64509
+ }
64510
+ }
64460
64511
  return type;
64461
64512
  }
64462
64513
  /**
@@ -64903,6 +64954,7 @@ var ts;
64903
64954
  return 0 /* False */;
64904
64955
  }
64905
64956
  function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
64957
+ var _a, _b;
64906
64958
  var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
64907
64959
  var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
64908
64960
  source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
@@ -64943,6 +64995,9 @@ var ts;
64943
64995
  return;
64944
64996
  }
64945
64997
  reportRelationError(headMessage, source, target);
64998
+ if (strictNullChecks && source.flags & 8650752 /* TypeVariable */ && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source) && isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */))) {
64999
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
65000
+ }
64946
65001
  }
64947
65002
  function traceUnionsOrIntersectionsTooLarge(source, target) {
64948
65003
  if (!ts.tracing) {
@@ -65729,13 +65784,6 @@ var ts;
65729
65784
  // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
65730
65785
  if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
65731
65786
  var constraint = getConstraintOfType(source) || unknownType;
65732
- if (!getConstraintOfType(source) || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
65733
- // A type variable with no constraint is not related to the non-primitive object type.
65734
- if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
65735
- resetErrorInfo(saveErrorInfo);
65736
- return result;
65737
- }
65738
- }
65739
65787
  // hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
65740
65788
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
65741
65789
  resetErrorInfo(saveErrorInfo);
@@ -67209,9 +67257,11 @@ var ts;
67209
67257
  return getSupertypeOrUnion(types);
67210
67258
  }
67211
67259
  var primaryTypes = ts.filter(types, function (t) { return !(t.flags & 98304 /* Nullable */); });
67212
- return primaryTypes.length ?
67213
- getNullableType(getSupertypeOrUnion(primaryTypes), getFalsyFlagsOfTypes(types) & 98304 /* Nullable */) :
67214
- getUnionType(types, 2 /* Subtype */);
67260
+ if (primaryTypes.length) {
67261
+ var supertypeOrUnion = getSupertypeOrUnion(primaryTypes);
67262
+ return primaryTypes === types ? supertypeOrUnion : getUnionType(__spreadArray([supertypeOrUnion], ts.filter(types, function (t) { return !!(t.flags & 98304 /* Nullable */); }), true));
67263
+ }
67264
+ return getUnionType(types, 2 /* Subtype */);
67215
67265
  }
67216
67266
  // Return the leftmost type for which no type to the right is a subtype.
67217
67267
  function getCommonSubtype(types) {
@@ -67410,12 +67460,13 @@ var ts;
67410
67460
  // flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
67411
67461
  // no flags for all other types (including non-falsy literal types).
67412
67462
  function getFalsyFlags(type) {
67413
- return type.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(type.types) :
67414
- type.flags & 128 /* StringLiteral */ ? type.value === "" ? 128 /* StringLiteral */ : 0 :
67415
- type.flags & 256 /* NumberLiteral */ ? type.value === 0 ? 256 /* NumberLiteral */ : 0 :
67416
- type.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(type) ? 2048 /* BigIntLiteral */ : 0 :
67417
- type.flags & 512 /* BooleanLiteral */ ? (type === falseType || type === regularFalseType) ? 512 /* BooleanLiteral */ : 0 :
67418
- type.flags & 117724 /* PossiblyFalsy */;
67463
+ var t = type.flags & 2097152 /* Intersection */ ? getBaseConstraintOrType(type) : type;
67464
+ return t.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(t.types) :
67465
+ t.flags & 128 /* StringLiteral */ ? t.value === "" ? 128 /* StringLiteral */ : 0 :
67466
+ t.flags & 256 /* NumberLiteral */ ? t.value === 0 ? 256 /* NumberLiteral */ : 0 :
67467
+ t.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(t) ? 2048 /* BigIntLiteral */ : 0 :
67468
+ t.flags & 512 /* BooleanLiteral */ ? (t === falseType || t === regularFalseType) ? 512 /* BooleanLiteral */ : 0 :
67469
+ t.flags & 117724 /* PossiblyFalsy */;
67419
67470
  }
67420
67471
  function removeDefinitelyFalsyTypes(type) {
67421
67472
  return getFalsyFlags(type) & 117632 /* DefinitelyFalsy */ ?
@@ -67455,20 +67506,22 @@ var ts;
67455
67506
  return type.flags & 32768 /* Undefined */ ? type : getUnionType([type, isProperty ? missingType : undefinedType]);
67456
67507
  }
67457
67508
  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 */);
67462
67509
  if (!deferredGlobalNonNullableTypeAlias) {
67463
67510
  deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable", 524288 /* TypeAlias */, /*diagnostic*/ undefined) || unknownSymbol;
67464
67511
  }
67465
- // If the NonNullable<T> type is available, return an instantiation. Otherwise just return the reduced type.
67466
67512
  return deferredGlobalNonNullableTypeAlias !== unknownSymbol ?
67467
- getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [reducedType]) :
67468
- reducedType;
67513
+ getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]) :
67514
+ getIntersectionType([type, emptyObjectType]);
67469
67515
  }
67470
67516
  function getNonNullableType(type) {
67471
- return strictNullChecks ? getGlobalNonNullableTypeInstantiation(type) : type;
67517
+ if (strictNullChecks) {
67518
+ // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67519
+ // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67520
+ // that isn't eliminated by a NonNullable<T> instantiation.
67521
+ var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67522
+ return maybeTypeOfKind(reducedType, 465829888 /* Instantiable */) ? getGlobalNonNullableTypeInstantiation(reducedType) : reducedType;
67523
+ }
67524
+ return type;
67472
67525
  }
67473
67526
  function addOptionalTypeMarker(type) {
67474
67527
  return strictNullChecks ? getUnionType([type, optionalType]) : type;
@@ -68149,13 +68202,40 @@ var ts;
68149
68202
  return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
68150
68203
  sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
68151
68204
  }
68152
- function isValidBigIntString(s) {
68205
+ /**
68206
+ * Tests whether the provided string can be parsed as a number.
68207
+ * @param s The string to test.
68208
+ * @param roundTripOnly Indicates the resulting number matches the input when converted back to a string.
68209
+ */
68210
+ function isValidNumberString(s, roundTripOnly) {
68211
+ if (s === "")
68212
+ return false;
68213
+ var n = +s;
68214
+ return isFinite(n) && (!roundTripOnly || "" + n === s);
68215
+ }
68216
+ /**
68217
+ * @param text a valid bigint string excluding a trailing `n`, but including a possible prefix `-`. Use `isValidBigIntString(text, roundTripOnly)` before calling this function.
68218
+ */
68219
+ function parseBigIntLiteralType(text) {
68220
+ var negative = text.startsWith("-");
68221
+ var base10Value = ts.parsePseudoBigInt((negative ? text.slice(1) : text) + "n");
68222
+ return getBigIntLiteralType({ negative: negative, base10Value: base10Value });
68223
+ }
68224
+ /**
68225
+ * Tests whether the provided string can be parsed as a bigint.
68226
+ * @param s The string to test.
68227
+ * @param roundTripOnly Indicates the resulting bigint matches the input when converted back to a string.
68228
+ */
68229
+ function isValidBigIntString(s, roundTripOnly) {
68230
+ if (s === "")
68231
+ return false;
68153
68232
  var scanner = ts.createScanner(99 /* ESNext */, /*skipTrivia*/ false);
68154
68233
  var success = true;
68155
68234
  scanner.setOnError(function () { return success = false; });
68156
68235
  scanner.setText(s + "n");
68157
68236
  var result = scanner.scan();
68158
- if (result === 40 /* MinusToken */) {
68237
+ var negative = result === 40 /* MinusToken */;
68238
+ if (negative) {
68159
68239
  result = scanner.scan();
68160
68240
  }
68161
68241
  var flags = scanner.getTokenFlags();
@@ -68164,7 +68244,8 @@ var ts;
68164
68244
  // * a bigint can be scanned, and that when it is scanned, it is
68165
68245
  // * the full length of the input string (so the scanner is one character beyond the augmented input length)
68166
68246
  // * it does not contain a numeric seperator (the `BigInt` constructor does not accept a numeric seperator in its input)
68167
- return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */);
68247
+ return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */)
68248
+ && (!roundTripOnly || s === ts.pseudoBigIntToString({ negative: negative, base10Value: ts.parsePseudoBigInt(scanner.getTokenValue()) }));
68168
68249
  }
68169
68250
  function isValidTypeForTemplateLiteralPlaceholder(source, target) {
68170
68251
  if (source === target || target.flags & (1 /* Any */ | 4 /* String */)) {
@@ -68172,8 +68253,8 @@ var ts;
68172
68253
  }
68173
68254
  if (source.flags & 128 /* StringLiteral */) {
68174
68255
  var value = source.value;
68175
- return !!(target.flags & 8 /* Number */ && value !== "" && isFinite(+value) ||
68176
- target.flags & 64 /* BigInt */ && value !== "" && isValidBigIntString(value) ||
68256
+ return !!(target.flags & 8 /* Number */ && isValidNumberString(value, /*roundTripOnly*/ false) ||
68257
+ target.flags & 64 /* BigInt */ && isValidBigIntString(value, /*roundTripOnly*/ false) ||
68177
68258
  target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName);
68178
68259
  }
68179
68260
  if (source.flags & 134217728 /* TemplateLiteral */) {
@@ -68746,8 +68827,57 @@ var ts;
68746
68827
  // upon instantiation, would collapse all the placeholders to just 'string', and an assignment check might
68747
68828
  // succeed. That would be a pointless and confusing outcome.
68748
68829
  if (matches || ts.every(target.texts, function (s) { return s.length === 0; })) {
68830
+ var _loop_23 = function (i) {
68831
+ var source_1 = matches ? matches[i] : neverType;
68832
+ var target_3 = types[i];
68833
+ // If we are inferring from a string literal type to a type variable whose constraint includes one of the
68834
+ // allowed template literal placeholder types, infer from a literal type corresponding to the constraint.
68835
+ if (source_1.flags & 128 /* StringLiteral */ && target_3.flags & 8650752 /* TypeVariable */) {
68836
+ var inferenceContext = getInferenceInfoForType(target_3);
68837
+ var constraint = inferenceContext ? getBaseConstraintOfType(inferenceContext.typeParameter) : undefined;
68838
+ if (constraint && !isTypeAny(constraint)) {
68839
+ var constraintTypes = constraint.flags & 1048576 /* Union */ ? constraint.types : [constraint];
68840
+ var allTypeFlags_1 = ts.reduceLeft(constraintTypes, function (flags, t) { return flags | t.flags; }, 0);
68841
+ // If the constraint contains `string`, we don't need to look for a more preferred type
68842
+ if (!(allTypeFlags_1 & 4 /* String */)) {
68843
+ var str_1 = source_1.value;
68844
+ // If the type contains `number` or a number literal and the string isn't a valid number, exclude numbers
68845
+ if (allTypeFlags_1 & 296 /* NumberLike */ && !isValidNumberString(str_1, /*roundTripOnly*/ true)) {
68846
+ allTypeFlags_1 &= ~296 /* NumberLike */;
68847
+ }
68848
+ // If the type contains `bigint` or a bigint literal and the string isn't a valid bigint, exclude bigints
68849
+ if (allTypeFlags_1 & 2112 /* BigIntLike */ && !isValidBigIntString(str_1, /*roundTripOnly*/ true)) {
68850
+ allTypeFlags_1 &= ~2112 /* BigIntLike */;
68851
+ }
68852
+ // for each type in the constraint, find the highest priority matching type
68853
+ var matchingType = ts.reduceLeft(constraintTypes, function (left, right) {
68854
+ return !(right.flags & allTypeFlags_1) ? left :
68855
+ left.flags & 4 /* String */ ? left : right.flags & 4 /* String */ ? source_1 :
68856
+ left.flags & 134217728 /* TemplateLiteral */ ? left : right.flags & 134217728 /* TemplateLiteral */ && isTypeMatchedByTemplateLiteralType(source_1, right) ? source_1 :
68857
+ left.flags & 268435456 /* StringMapping */ ? left : right.flags & 268435456 /* StringMapping */ && str_1 === applyStringMapping(right.symbol, str_1) ? source_1 :
68858
+ left.flags & 128 /* StringLiteral */ ? left : right.flags & 128 /* StringLiteral */ && right.value === str_1 ? right :
68859
+ left.flags & 8 /* Number */ ? left : right.flags & 8 /* Number */ ? getNumberLiteralType(+str_1) :
68860
+ left.flags & 32 /* Enum */ ? left : right.flags & 32 /* Enum */ ? getNumberLiteralType(+str_1) :
68861
+ left.flags & 256 /* NumberLiteral */ ? left : right.flags & 256 /* NumberLiteral */ && right.value === +str_1 ? right :
68862
+ left.flags & 64 /* BigInt */ ? left : right.flags & 64 /* BigInt */ ? parseBigIntLiteralType(str_1) :
68863
+ left.flags & 2048 /* BigIntLiteral */ ? left : right.flags & 2048 /* BigIntLiteral */ && ts.pseudoBigIntToString(right.value) === str_1 ? right :
68864
+ left.flags & 16 /* Boolean */ ? left : right.flags & 16 /* Boolean */ ? str_1 === "true" ? trueType : str_1 === "false" ? falseType : booleanType :
68865
+ left.flags & 512 /* BooleanLiteral */ ? left : right.flags & 512 /* BooleanLiteral */ && right.intrinsicName === str_1 ? right :
68866
+ left.flags & 32768 /* Undefined */ ? left : right.flags & 32768 /* Undefined */ && right.intrinsicName === str_1 ? right :
68867
+ left.flags & 65536 /* Null */ ? left : right.flags & 65536 /* Null */ && right.intrinsicName === str_1 ? right :
68868
+ left;
68869
+ }, neverType);
68870
+ if (!(matchingType.flags & 131072 /* Never */)) {
68871
+ inferFromTypes(matchingType, target_3);
68872
+ return "continue";
68873
+ }
68874
+ }
68875
+ }
68876
+ }
68877
+ inferFromTypes(source_1, target_3);
68878
+ };
68749
68879
  for (var i = 0; i < types.length; i++) {
68750
- inferFromTypes(matches ? matches[i] : neverType, types[i]);
68880
+ _loop_23(i);
68751
68881
  }
68752
68882
  }
68753
68883
  }
@@ -69265,7 +69395,7 @@ var ts;
69265
69395
  function mapTypesByKeyProperty(types, name) {
69266
69396
  var map = new ts.Map();
69267
69397
  var count = 0;
69268
- var _loop_23 = function (type) {
69398
+ var _loop_24 = function (type) {
69269
69399
  if (type.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 58982400 /* InstantiableNonPrimitive */)) {
69270
69400
  var discriminant = getTypeOfPropertyOfType(type, name);
69271
69401
  if (discriminant) {
@@ -69291,7 +69421,7 @@ var ts;
69291
69421
  };
69292
69422
  for (var _i = 0, types_16 = types; _i < types_16.length; _i++) {
69293
69423
  var type = types_16[_i];
69294
- var state_9 = _loop_23(type);
69424
+ var state_9 = _loop_24(type);
69295
69425
  if (typeof state_9 === "object")
69296
69426
  return state_9.value;
69297
69427
  }
@@ -69499,6 +69629,24 @@ var ts;
69499
69629
  function getTypeWithFacts(type, include) {
69500
69630
  return filterType(type, function (t) { return (getTypeFacts(t) & include) !== 0; });
69501
69631
  }
69632
+ function getIntersectionWithFacts(type, facts) {
69633
+ var reduced = recombineUnknownType(getTypeWithFacts(strictNullChecks && type.flags & 2 /* Unknown */ ? unknownUnionType : type, facts));
69634
+ if (strictNullChecks) {
69635
+ switch (facts) {
69636
+ case 524288 /* NEUndefined */:
69637
+ 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; });
69638
+ case 1048576 /* NENull */:
69639
+ 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; });
69640
+ case 2097152 /* NEUndefinedOrNull */:
69641
+ case 4194304 /* Truthy */:
69642
+ return mapType(reduced, function (t) { return getTypeFacts(t) & 262144 /* EQUndefinedOrNull */ ? getGlobalNonNullableTypeInstantiation(t) : t; });
69643
+ }
69644
+ }
69645
+ return reduced;
69646
+ }
69647
+ function recombineUnknownType(type) {
69648
+ return type === unknownUnionType ? unknownType : type;
69649
+ }
69502
69650
  function getTypeWithDefault(type, defaultExpression) {
69503
69651
  return defaultExpression ?
69504
69652
  getUnionType([getNonUndefinedType(type), getTypeOfExpression(defaultExpression)]) :
@@ -70556,7 +70704,7 @@ var ts;
70556
70704
  if (isEvolvingArrayTypeList(types)) {
70557
70705
  return getEvolvingArrayType(getUnionType(ts.map(types, getElementTypeOfEvolvingArrayType)));
70558
70706
  }
70559
- var result = getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction);
70707
+ var result = recombineUnknownType(getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction));
70560
70708
  if (result !== declaredType && result.flags & declaredType.flags & 1048576 /* Union */ && ts.arraysEqual(result.types, declaredType.types)) {
70561
70709
  return declaredType;
70562
70710
  }
@@ -70658,8 +70806,7 @@ var ts;
70658
70806
  }
70659
70807
  function narrowTypeByTruthiness(type, expr, assumeTrue) {
70660
70808
  if (isMatchingReference(reference, expr)) {
70661
- return type.flags & 2 /* Unknown */ && assumeTrue ? nonNullUnknownType :
70662
- getTypeWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70809
+ return getIntersectionWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70663
70810
  }
70664
70811
  if (strictNullChecks && assumeTrue && optionalChainContainsReference(expr, reference)) {
70665
70812
  type = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
@@ -70812,9 +70959,6 @@ var ts;
70812
70959
  assumeTrue = !assumeTrue;
70813
70960
  }
70814
70961
  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
- }
70818
70962
  if ((type.flags & 2 /* Unknown */) && assumeTrue && (operator === 36 /* EqualsEqualsEqualsToken */ || operator === 37 /* ExclamationEqualsEqualsToken */)) {
70819
70963
  if (valueType.flags & (131068 /* Primitive */ | 67108864 /* NonPrimitive */)) {
70820
70964
  return valueType;
@@ -70834,7 +70978,7 @@ var ts;
70834
70978
  valueType.flags & 65536 /* Null */ ?
70835
70979
  assumeTrue ? 131072 /* EQNull */ : 1048576 /* NENull */ :
70836
70980
  assumeTrue ? 65536 /* EQUndefined */ : 524288 /* NEUndefined */;
70837
- return type.flags & 2 /* Unknown */ && facts & (1048576 /* NENull */ | 2097152 /* NEUndefinedOrNull */) ? nonNullUnknownType : getTypeWithFacts(type, facts);
70981
+ return getIntersectionWithFacts(type, facts);
70838
70982
  }
70839
70983
  if (assumeTrue) {
70840
70984
  var filterFn = operator === 34 /* EqualsEqualsToken */ ?
@@ -70862,17 +71006,11 @@ var ts;
70862
71006
  if (type.flags & 1 /* Any */ && literal.text === "function") {
70863
71007
  return type;
70864
71008
  }
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
- }
70871
71009
  var facts = assumeTrue ?
70872
71010
  typeofEQFacts.get(literal.text) || 128 /* TypeofEQHostObject */ :
70873
71011
  typeofNEFacts.get(literal.text) || 32768 /* TypeofNEHostObject */;
70874
71012
  var impliedType = getImpliedTypeFromTypeofGuard(type, literal.text);
70875
- return getTypeWithFacts(assumeTrue && impliedType ? mapType(type, narrowUnionMemberByTypeof(impliedType)) : type, facts);
71013
+ return getTypeWithFacts(assumeTrue && impliedType ? narrowTypeByImpliedType(type, impliedType) : type, facts);
70876
71014
  }
70877
71015
  function narrowTypeBySwitchOptionalChainContainment(type, switchStatement, clauseStart, clauseEnd, clauseCheck) {
70878
71016
  var everyClauseChecks = clauseStart !== clauseEnd && ts.every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), clauseCheck);
@@ -70921,10 +71059,10 @@ var ts;
70921
71059
  }
70922
71060
  function getImpliedTypeFromTypeofGuard(type, text) {
70923
71061
  switch (text) {
71062
+ case "object":
71063
+ return type.flags & 1 /* Any */ ? type : getUnionType([nullType, nonPrimitiveType]);
70924
71064
  case "function":
70925
71065
  return type.flags & 1 /* Any */ ? type : globalFunctionType;
70926
- case "object":
70927
- return type.flags & 2 /* Unknown */ ? getUnionType([nonPrimitiveType, nullType]) : type;
70928
71066
  default:
70929
71067
  return typeofTypesByName.get(text);
70930
71068
  }
@@ -70935,22 +71073,27 @@ var ts;
70935
71073
  // the guard. For example: narrowing `{} | undefined` by `"boolean"` should produce the type `boolean`, not
70936
71074
  // the filtered type `{}`. For this reason we narrow constituents of the union individually, in addition to
70937
71075
  // filtering by type-facts.
70938
- function narrowUnionMemberByTypeof(candidate) {
70939
- return function (type) {
70940
- if (isTypeSubtypeOf(type, candidate)) {
70941
- return type;
70942
- }
70943
- if (isTypeSubtypeOf(candidate, type)) {
70944
- return candidate;
71076
+ function narrowTypeByImpliedType(type, candidate) {
71077
+ if (type.flags & 3 /* AnyOrUnknown */) {
71078
+ return candidate;
71079
+ }
71080
+ return mapType(type, function (t) {
71081
+ if (isTypeRelatedTo(t, candidate, strictSubtypeRelation)) {
71082
+ return t;
70945
71083
  }
70946
- if (type.flags & 465829888 /* Instantiable */) {
70947
- var constraint = getBaseConstraintOfType(type) || anyType;
70948
- if (isTypeSubtypeOf(candidate, constraint)) {
70949
- return getIntersectionType([type, candidate]);
71084
+ return mapType(candidate, function (c) {
71085
+ if (!areTypesComparable(t, c)) {
71086
+ return neverType;
70950
71087
  }
70951
- }
70952
- return type;
70953
- };
71088
+ if (c.flags & 131068 /* Primitive */ && t.flags & 524288 /* Object */ && !isEmptyAnonymousObjectType(t)) {
71089
+ return isTypeSubtypeOf(c, t) ? c : neverType;
71090
+ }
71091
+ if (c === globalFunctionType && isTypeSubtypeOf(c, t)) {
71092
+ return c;
71093
+ }
71094
+ return getIntersectionType([t, c]);
71095
+ });
71096
+ });
70954
71097
  }
70955
71098
  function narrowBySwitchOnTypeOf(type, switchStatement, clauseStart, clauseEnd) {
70956
71099
  var switchWitnesses = getSwitchClauseTypeOfWitnesses(switchStatement, /*retainDefault*/ true);
@@ -71009,7 +71152,7 @@ var ts;
71009
71152
  because it is caught in the first clause.
71010
71153
  */
71011
71154
  var impliedType = getTypeWithFacts(getUnionType(clauseWitnesses.map(function (text) { return getImpliedTypeFromTypeofGuard(type, text) || type; })), switchFacts);
71012
- return getTypeWithFacts(mapType(type, narrowUnionMemberByTypeof(impliedType)), switchFacts);
71155
+ return getTypeWithFacts(narrowTypeByImpliedType(type, impliedType), switchFacts);
71013
71156
  }
71014
71157
  function isMatchingConstructorReference(expr) {
71015
71158
  return (ts.isPropertyAccessExpression(expr) && ts.idText(expr.name) === "constructor" ||
@@ -71313,7 +71456,9 @@ var ts;
71313
71456
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
71314
71457
  }
71315
71458
  function isGenericTypeWithUnionConstraint(type) {
71316
- return !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71459
+ return type.flags & 2097152 /* Intersection */ ?
71460
+ ts.some(type.types, isGenericTypeWithUnionConstraint) :
71461
+ !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71317
71462
  }
71318
71463
  function isGenericTypeWithoutNullableConstraint(type) {
71319
71464
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
@@ -71341,7 +71486,7 @@ var ts;
71341
71486
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
71342
71487
  someType(type, isGenericTypeWithUnionConstraint) &&
71343
71488
  (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
71344
- return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ ? getBaseConstraintOrType(t) : t; }) : type;
71489
+ return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
71345
71490
  }
71346
71491
  function isExportOrExportExpression(location) {
71347
71492
  return !!ts.findAncestor(location, function (n) {
@@ -75679,7 +75824,7 @@ var ts;
75679
75824
  if (spreadIndex >= 0) {
75680
75825
  // Create synthetic arguments from spreads of tuple types.
75681
75826
  var effectiveArgs_1 = args.slice(0, spreadIndex);
75682
- var _loop_24 = function (i) {
75827
+ var _loop_25 = function (i) {
75683
75828
  var arg = args[i];
75684
75829
  // We can call checkExpressionCached because spread expressions never have a contextual type.
75685
75830
  var spreadType = arg.kind === 225 /* SpreadElement */ && (flowLoopCount ? checkExpression(arg.expression) : checkExpressionCached(arg.expression));
@@ -75696,7 +75841,7 @@ var ts;
75696
75841
  }
75697
75842
  };
75698
75843
  for (var i = spreadIndex; i < args.length; i++) {
75699
- _loop_24(i);
75844
+ _loop_25(i);
75700
75845
  }
75701
75846
  return effectiveArgs_1;
75702
75847
  }
@@ -76016,7 +76161,7 @@ var ts;
76016
76161
  var min_3 = Number.MAX_VALUE;
76017
76162
  var minIndex = 0;
76018
76163
  var i_1 = 0;
76019
- var _loop_25 = function (c) {
76164
+ var _loop_26 = function (c) {
76020
76165
  var chain_2 = function () { return ts.chainDiagnosticMessages(/*details*/ undefined, ts.Diagnostics.Overload_0_of_1_2_gave_the_following_error, i_1 + 1, candidates.length, signatureToString(c)); };
76021
76166
  var diags_2 = getSignatureApplicabilityError(node, args, c, assignableRelation, 0 /* Normal */, /*reportErrors*/ true, chain_2);
76022
76167
  if (diags_2) {
@@ -76034,7 +76179,7 @@ var ts;
76034
76179
  };
76035
76180
  for (var _a = 0, candidatesForArgumentError_1 = candidatesForArgumentError; _a < candidatesForArgumentError_1.length; _a++) {
76036
76181
  var c = candidatesForArgumentError_1[_a];
76037
- _loop_25(c);
76182
+ _loop_26(c);
76038
76183
  }
76039
76184
  var diags_3 = max > 1 ? allDiagnostics[minIndex] : ts.flatten(allDiagnostics);
76040
76185
  ts.Debug.assert(diags_3.length > 0, "No errors reported for 3 or fewer overload signatures");
@@ -76192,7 +76337,7 @@ var ts;
76192
76337
  }
76193
76338
  var _a = ts.minAndMax(candidates, getNumNonRestParameters), minArgumentCount = _a.min, maxNonRestParam = _a.max;
76194
76339
  var parameters = [];
76195
- var _loop_26 = function (i) {
76340
+ var _loop_27 = function (i) {
76196
76341
  var symbols = ts.mapDefined(candidates, function (s) { return signatureHasRestParameter(s) ?
76197
76342
  i < s.parameters.length - 1 ? s.parameters[i] : ts.last(s.parameters) :
76198
76343
  i < s.parameters.length ? s.parameters[i] : undefined; });
@@ -76200,7 +76345,7 @@ var ts;
76200
76345
  parameters.push(createCombinedSymbolFromTypes(symbols, ts.mapDefined(candidates, function (candidate) { return tryGetTypeAtPosition(candidate, i); })));
76201
76346
  };
76202
76347
  for (var i = 0; i < maxNonRestParam; i++) {
76203
- _loop_26(i);
76348
+ _loop_27(i);
76204
76349
  }
76205
76350
  var restParameterSymbols = ts.mapDefined(candidates, function (c) { return signatureHasRestParameter(c) ? ts.last(c.parameters) : undefined; });
76206
76351
  var flags = 0 /* None */;
@@ -80257,7 +80402,7 @@ var ts;
80257
80402
  var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
80258
80403
  if (indexSymbol === null || indexSymbol === void 0 ? void 0 : indexSymbol.declarations) {
80259
80404
  var indexSignatureMap_1 = new ts.Map();
80260
- var _loop_27 = function (declaration) {
80405
+ var _loop_28 = function (declaration) {
80261
80406
  if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
80262
80407
  forEachType(getTypeFromTypeNode(declaration.parameters[0].type), function (type) {
80263
80408
  var entry = indexSignatureMap_1.get(getTypeId(type));
@@ -80272,7 +80417,7 @@ var ts;
80272
80417
  };
80273
80418
  for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
80274
80419
  var declaration = _a[_i];
80275
- _loop_27(declaration);
80420
+ _loop_28(declaration);
80276
80421
  }
80277
80422
  indexSignatureMap_1.forEach(function (entry) {
80278
80423
  if (entry.declarations.length > 1) {
@@ -82468,7 +82613,7 @@ var ts;
82468
82613
  }
82469
82614
  // For a commonjs `const x = require`, validate the alias and exit
82470
82615
  var symbol = getSymbolOfNode(node);
82471
- if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
82616
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* BindingElement */ ? node.parent.parent : node)) {
82472
82617
  checkAliasSymbol(node);
82473
82618
  return;
82474
82619
  }
@@ -83733,7 +83878,7 @@ var ts;
83733
83878
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83734
83879
  var localPropDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
83735
83880
  name && name.kind === 162 /* ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
83736
- var _loop_28 = function (info) {
83881
+ var _loop_29 = function (info) {
83737
83882
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
83738
83883
  // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
83739
83884
  // in the containing type, or (c) the containing type is an interface and no base interface contains both the property and
@@ -83746,7 +83891,7 @@ var ts;
83746
83891
  };
83747
83892
  for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
83748
83893
  var info = indexInfos_9[_i];
83749
- _loop_28(info);
83894
+ _loop_29(info);
83750
83895
  }
83751
83896
  }
83752
83897
  function checkIndexConstraintForIndexSignature(type, checkInfo) {
@@ -83754,7 +83899,7 @@ var ts;
83754
83899
  var indexInfos = getApplicableIndexInfos(type, checkInfo.keyType);
83755
83900
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83756
83901
  var localCheckDeclaration = declaration && getParentOfSymbol(getSymbolOfNode(declaration)) === type.symbol ? declaration : undefined;
83757
- var _loop_29 = function (info) {
83902
+ var _loop_30 = function (info) {
83758
83903
  if (info === checkInfo)
83759
83904
  return "continue";
83760
83905
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
@@ -83769,7 +83914,7 @@ var ts;
83769
83914
  };
83770
83915
  for (var _i = 0, indexInfos_10 = indexInfos; _i < indexInfos_10.length; _i++) {
83771
83916
  var info = indexInfos_10[_i];
83772
- _loop_29(info);
83917
+ _loop_30(info);
83773
83918
  }
83774
83919
  }
83775
83920
  function checkTypeNameIsReserved(name, message) {
@@ -84088,7 +84233,7 @@ var ts;
84088
84233
  var baseTypes = baseTypeNode && getBaseTypes(type);
84089
84234
  var baseWithThis = (baseTypes === null || baseTypes === void 0 ? void 0 : baseTypes.length) ? getTypeWithThisArgument(ts.first(baseTypes), type.thisType) : undefined;
84090
84235
  var baseStaticType = getBaseConstructorTypeOfClass(type);
84091
- var _loop_30 = function (member) {
84236
+ var _loop_31 = function (member) {
84092
84237
  if (ts.hasAmbientModifier(member)) {
84093
84238
  return "continue";
84094
84239
  }
@@ -84105,7 +84250,7 @@ var ts;
84105
84250
  };
84106
84251
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84107
84252
  var member = _a[_i];
84108
- _loop_30(member);
84253
+ _loop_31(member);
84109
84254
  }
84110
84255
  }
84111
84256
  /**
@@ -84193,7 +84338,7 @@ var ts;
84193
84338
  function issueMemberSpecificError(node, typeWithThis, baseWithThis, broadDiag) {
84194
84339
  // iterate over all implemented properties and issue errors on each one which isn't compatible, rather than the class as a whole, if possible
84195
84340
  var issuedMemberError = false;
84196
- var _loop_31 = function (member) {
84341
+ var _loop_32 = function (member) {
84197
84342
  if (ts.isStatic(member)) {
84198
84343
  return "continue";
84199
84344
  }
@@ -84212,7 +84357,7 @@ var ts;
84212
84357
  };
84213
84358
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84214
84359
  var member = _a[_i];
84215
- _loop_31(member);
84360
+ _loop_32(member);
84216
84361
  }
84217
84362
  if (!issuedMemberError) {
84218
84363
  // check again with diagnostics to generate a less-specific error
@@ -122180,7 +122325,7 @@ var ts;
122180
122325
  });
122181
122326
  // Sort by paths closest to importing file Name directory
122182
122327
  var sortedPaths = [];
122183
- var _loop_32 = function (directory) {
122328
+ var _loop_33 = function (directory) {
122184
122329
  var directoryStart = ts.ensureTrailingDirectorySeparator(directory);
122185
122330
  var pathsInDirectory;
122186
122331
  allFileNames.forEach(function (_a, fileName) {
@@ -122204,7 +122349,7 @@ var ts;
122204
122349
  };
122205
122350
  var out_directory_1;
122206
122351
  for (var directory = ts.getDirectoryPath(importingFileName); allFileNames.size !== 0;) {
122207
- var state_10 = _loop_32(directory);
122352
+ var state_10 = _loop_33(directory);
122208
122353
  directory = out_directory_1;
122209
122354
  if (state_10 === "break")
122210
122355
  break;
@@ -136332,7 +136477,7 @@ var ts;
136332
136477
  ts.Debug.assert(parent.name === node);
136333
136478
  return true;
136334
136479
  case 203 /* BindingElement */:
136335
- return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent);
136480
+ return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent.parent.parent);
136336
136481
  default:
136337
136482
  return false;
136338
136483
  }
@@ -137798,7 +137943,7 @@ var ts;
137798
137943
  // Use the parent symbol if the location is commonjs require syntax on javascript files only.
137799
137944
  if (ts.isInJSFile(referenceLocation)
137800
137945
  && referenceLocation.parent.kind === 203 /* BindingElement */
137801
- && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) {
137946
+ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent.parent.parent)) {
137802
137947
  referenceSymbol = referenceLocation.parent.symbol;
137803
137948
  // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In
137804
137949
  // this case, just skip it, since the bound identifiers are not an alias of the import.
@@ -147174,11 +147319,9 @@ var ts;
147174
147319
  if (listEndToken !== 0 /* Unknown */ && formattingScanner.isOnToken() && formattingScanner.getStartPos() < originalRange.end) {
147175
147320
  var tokenInfo = formattingScanner.readTokenInfo(parent);
147176
147321
  if (tokenInfo.token.kind === 27 /* CommaToken */ && ts.isCallLikeExpression(parent)) {
147177
- var commaTokenLine = sourceFile.getLineAndCharacterOfPosition(tokenInfo.token.pos).line;
147178
- if (startLine !== commaTokenLine) {
147179
- formattingScanner.advance();
147180
- tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
147181
- }
147322
+ // consume the comma
147323
+ consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
147324
+ tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
147182
147325
  }
147183
147326
  // consume the list end token only if it is still belong to the parent
147184
147327
  // there might be the case when current token matches end token but does not considered as one
@@ -174884,6 +175027,7 @@ var ts;
174884
175027
  return info && !info.isLocal ? { fileName: info.fileName, pos: info.textSpan.start } : undefined;
174885
175028
  }
174886
175029
  function getReferencesWorker(projects, defaultProject, initialLocation, logger) {
175030
+ var _a;
174887
175031
  var perProjectResults = getPerProjectReferences(projects, defaultProject, initialLocation,
174888
175032
  /*isForRename*/ false, function (project, position) {
174889
175033
  logger.info("Finding references to " + position.fileName + " position " + position.pos + " in project " + project.getProjectName());
@@ -174903,7 +175047,7 @@ var ts;
174903
175047
  // have started the other project searches from related symbols. Propagate the
174904
175048
  // correct results to all other projects.
174905
175049
  var defaultProjectResults = perProjectResults.get(defaultProject);
174906
- if (defaultProjectResults[0].references[0].isDefinition === undefined) {
175050
+ if (((_a = defaultProjectResults === null || defaultProjectResults === void 0 ? void 0 : defaultProjectResults[0].references[0]) === null || _a === void 0 ? void 0 : _a.isDefinition) === undefined) {
174907
175051
  // Clear all isDefinition properties
174908
175052
  perProjectResults.forEach(function (projectResults) {
174909
175053
  for (var _i = 0, projectResults_2 = projectResults; _i < projectResults_2.length; _i++) {
@@ -174920,8 +175064,8 @@ var ts;
174920
175064
  var knownSymbolSpans_1 = createDocumentSpanSet();
174921
175065
  for (var _i = 0, defaultProjectResults_1 = defaultProjectResults; _i < defaultProjectResults_1.length; _i++) {
174922
175066
  var referencedSymbol = defaultProjectResults_1[_i];
174923
- for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
174924
- var ref = _b[_a];
175067
+ for (var _b = 0, _c = referencedSymbol.references; _b < _c.length; _b++) {
175068
+ var ref = _c[_b];
174925
175069
  if (ref.isDefinition) {
174926
175070
  knownSymbolSpans_1.add(ref);
174927
175071
  // One is enough - updateIsDefinitionOfReferencedSymbols will fill out the set based on symbols
@@ -175081,11 +175225,9 @@ var ts;
175081
175225
  // it easier for the caller to skip post-processing.
175082
175226
  if (searchedProjects.size === 1) {
175083
175227
  var it = resultsMap.values().next();
175084
- ts.Debug.assert(!it.done);
175085
- return it.value;
175228
+ return it.done ? server.emptyArray : it.value; // There may not be any results at all
175086
175229
  }
175087
175230
  return resultsMap;
175088
- // May enqueue to otherPositionQueue
175089
175231
  function searchPosition(project, location) {
175090
175232
  var projectResults = getResultsForPosition(project, location);
175091
175233
  if (!projectResults)