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.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220526";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220529";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -5295,6 +5295,11 @@ var ts;
5295
5295
  // Flags that require TypeFlags.Union
5296
5296
  /* @internal */
5297
5297
  ObjectFlags[ObjectFlags["ContainsIntersections"] = 16777216] = "ContainsIntersections";
5298
+ /* @internal */
5299
+ ObjectFlags[ObjectFlags["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
5300
+ /* @internal */
5301
+ ObjectFlags[ObjectFlags["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
5302
+ /* @internal */
5298
5303
  // Flags that require TypeFlags.Intersection
5299
5304
  /* @internal */
5300
5305
  ObjectFlags[ObjectFlags["IsNeverIntersectionComputed"] = 16777216] = "IsNeverIntersectionComputed";
@@ -8608,6 +8613,7 @@ var ts;
8608
8613
  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),
8609
8614
  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."),
8610
8615
  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."),
8616
+ 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."),
8611
8617
  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."),
8612
8618
  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."),
8613
8619
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
@@ -16412,9 +16418,6 @@ var ts;
16412
16418
  }
16413
16419
  ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire;
16414
16420
  function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
16415
- if (node.kind === 203 /* BindingElement */) {
16416
- node = node.parent.parent;
16417
- }
16418
16421
  return ts.isVariableDeclaration(node) &&
16419
16422
  !!node.initializer &&
16420
16423
  isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true);
@@ -20226,8 +20229,9 @@ var ts;
20226
20229
  */
20227
20230
  function isFileForcedToBeModuleByFormat(file) {
20228
20231
  // Excludes declaration files - they still require an explicit `export {}` or the like
20229
- // for back compat purposes.
20230
- return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined;
20232
+ // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
20233
+ // that aren't esm-mode (meaning not in a `type: module` scope).
20234
+ return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) && !file.isDeclarationFile ? true : undefined;
20231
20235
  }
20232
20236
  function getSetExternalModuleIndicator(options) {
20233
20237
  // TODO: Should this callback be cached?
@@ -20235,7 +20239,7 @@ var ts;
20235
20239
  case ts.ModuleDetectionKind.Force:
20236
20240
  // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule
20237
20241
  return function (file) {
20238
- file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file);
20242
+ file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined;
20239
20243
  };
20240
20244
  case ts.ModuleDetectionKind.Legacy:
20241
20245
  // Files are modules if they have imports, exports, or import.meta
@@ -20295,7 +20299,8 @@ var ts;
20295
20299
  }
20296
20300
  ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind;
20297
20301
  function getEmitModuleDetectionKind(options) {
20298
- return options.moduleDetection || ts.ModuleDetectionKind.Auto;
20302
+ return options.moduleDetection ||
20303
+ (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto);
20299
20304
  }
20300
20305
  ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind;
20301
20306
  function hasJsonModuleEmitEnabled(options) {
@@ -47140,12 +47145,14 @@ var ts;
47140
47145
  }
47141
47146
  }
47142
47147
  function setCommonJsModuleIndicator(node) {
47143
- if (file.externalModuleIndicator) {
47148
+ if (file.externalModuleIndicator && file.externalModuleIndicator !== true) {
47144
47149
  return false;
47145
47150
  }
47146
47151
  if (!file.commonJsModuleIndicator) {
47147
47152
  file.commonJsModuleIndicator = node;
47148
- bindSourceFileAsExternalModule();
47153
+ if (!file.externalModuleIndicator) {
47154
+ bindSourceFileAsExternalModule();
47155
+ }
47149
47156
  }
47150
47157
  return true;
47151
47158
  }
@@ -47559,7 +47566,11 @@ var ts;
47559
47566
  checkStrictModeEvalOrArguments(node, node.name);
47560
47567
  }
47561
47568
  if (!ts.isBindingPattern(node.name)) {
47562
- if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
47569
+ var possibleVariableDecl = node.kind === 254 /* VariableDeclaration */ ? node : node.parent.parent;
47570
+ if (ts.isInJSFile(node) &&
47571
+ ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) &&
47572
+ !ts.getJSDocTypeTag(node) &&
47573
+ !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
47563
47574
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
47564
47575
  }
47565
47576
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -48736,6 +48747,7 @@ var ts;
48736
48747
  var emptyTypeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type" /* Type */);
48737
48748
  emptyTypeLiteralSymbol.members = ts.createSymbolTable();
48738
48749
  var emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48750
+ var unknownUnionType = strictNullChecks ? getUnionType([undefinedType, nullType, createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray)]) : unknownType;
48739
48751
  var emptyGenericType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48740
48752
  emptyGenericType.instantiations = new ts.Map();
48741
48753
  var anyFunctionType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
@@ -50386,7 +50398,8 @@ var ts;
50386
50398
  && isAliasableOrJsExpression(node.parent.right)
50387
50399
  || node.kind === 297 /* ShorthandPropertyAssignment */
50388
50400
  || node.kind === 296 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
50389
- || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
50401
+ || node.kind === 254 /* VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)
50402
+ || node.kind === 203 /* BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent);
50390
50403
  }
50391
50404
  function isAliasableOrJsExpression(e) {
50392
50405
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50479,7 +50492,7 @@ var ts;
50479
50492
  return hasExportAssignmentSymbol(moduleSymbol);
50480
50493
  }
50481
50494
  // 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
50482
- return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias);
50495
+ return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias);
50483
50496
  }
50484
50497
  function getTargetOfImportClause(node, dontResolveAlias) {
50485
50498
  var _a;
@@ -58905,7 +58918,7 @@ var ts;
58905
58918
  }
58906
58919
  }
58907
58920
  }
58908
- else if (t.flags & 469892092 /* DisjointDomains */) {
58921
+ else if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58909
58922
  hasDisjointDomainType = true;
58910
58923
  }
58911
58924
  }
@@ -58917,7 +58930,7 @@ var ts;
58917
58930
  // intersection operation to reduce the union constraints.
58918
58931
  for (var _a = 0, types_6 = types; _a < types_6.length; _a++) {
58919
58932
  var t = types_6[_a];
58920
- if (t.flags & 469892092 /* DisjointDomains */) {
58933
+ if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58921
58934
  constraints = ts.append(constraints, t);
58922
58935
  }
58923
58936
  }
@@ -61466,7 +61479,7 @@ var ts;
61466
61479
  }
61467
61480
  return includes;
61468
61481
  }
61469
- function removeRedundantPrimitiveTypes(types, includes) {
61482
+ function removeRedundantSupertypes(types, includes) {
61470
61483
  var i = types.length;
61471
61484
  while (i > 0) {
61472
61485
  i--;
@@ -61474,7 +61487,9 @@ var ts;
61474
61487
  var remove = t.flags & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61475
61488
  t.flags & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61476
61489
  t.flags & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61477
- t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */;
61490
+ t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61491
+ t.flags & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61492
+ isEmptyAnonymousObjectType(t) && includes & 470302716 /* DefinitelyNonNullable */;
61478
61493
  if (remove) {
61479
61494
  ts.orderedRemoveItemAt(types, i);
61480
61495
  }
@@ -61596,7 +61611,7 @@ var ts;
61596
61611
  // a type alias of the form "type List<T> = T & { next: List<T> }" cannot be reduced during its declaration.
61597
61612
  // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
61598
61613
  // for intersections of types with signatures can be deterministic.
61599
- function getIntersectionType(types, aliasSymbol, aliasTypeArguments) {
61614
+ function getIntersectionType(types, aliasSymbol, aliasTypeArguments, noSupertypeReduction) {
61600
61615
  var typeMembershipMap = new ts.Map();
61601
61616
  var includes = addTypesToIntersection(typeMembershipMap, 0, types);
61602
61617
  var typeSet = ts.arrayFrom(typeMembershipMap.values());
@@ -61633,11 +61648,11 @@ var ts;
61633
61648
  if (includes & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61634
61649
  includes & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61635
61650
  includes & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61636
- includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */) {
61637
- removeRedundantPrimitiveTypes(typeSet, includes);
61638
- }
61639
- if (includes & 16777216 /* IncludesEmptyObject */ && includes & 524288 /* Object */) {
61640
- ts.orderedRemoveItemAt(typeSet, ts.findIndex(typeSet, isEmptyAnonymousObjectType));
61651
+ includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61652
+ includes & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61653
+ includes & 16777216 /* IncludesEmptyObject */ && includes & 470302716 /* DefinitelyNonNullable */) {
61654
+ if (!noSupertypeReduction)
61655
+ removeRedundantSupertypes(typeSet, includes);
61641
61656
  }
61642
61657
  if (includes & 262144 /* IncludesMissingType */) {
61643
61658
  typeSet[typeSet.indexOf(undefinedType)] = missingType;
@@ -61676,8 +61691,9 @@ var ts;
61676
61691
  }
61677
61692
  var constituents = getCrossProductIntersections(typeSet);
61678
61693
  // We attach a denormalized origin type when at least one constituent of the cross-product union is an
61679
- // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions).
61680
- var origin = ts.some(constituents, function (t) { return !!(t.flags & 2097152 /* Intersection */); }) ? createOriginUnionOrIntersectionType(2097152 /* Intersection */, typeSet) : undefined;
61694
+ // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions) and
61695
+ // the denormalized origin has fewer constituents than the union itself.
61696
+ var origin = ts.some(constituents, function (t) { return !!(t.flags & 2097152 /* Intersection */); }) && getConstituentCountOfTypes(constituents) > getConstituentCountOfTypes(typeSet) ? createOriginUnionOrIntersectionType(2097152 /* Intersection */, typeSet) : undefined;
61681
61697
  result = getUnionType(constituents, 1 /* Literal */, aliasSymbol, aliasTypeArguments, origin);
61682
61698
  }
61683
61699
  }
@@ -61720,11 +61736,21 @@ var ts;
61720
61736
  }
61721
61737
  return intersections;
61722
61738
  }
61739
+ function getConstituentCount(type) {
61740
+ return !(type.flags & 3145728 /* UnionOrIntersection */) || type.aliasSymbol ? 1 :
61741
+ type.flags & 1048576 /* Union */ && type.origin ? getConstituentCount(type.origin) :
61742
+ getConstituentCountOfTypes(type.types);
61743
+ }
61744
+ function getConstituentCountOfTypes(types) {
61745
+ return ts.reduceLeft(types, function (n, t) { return n + getConstituentCount(t); }, 0);
61746
+ }
61723
61747
  function getTypeFromIntersectionTypeNode(node) {
61724
61748
  var links = getNodeLinks(node);
61725
61749
  if (!links.resolvedType) {
61726
61750
  var aliasSymbol = getAliasSymbolForTypeNode(node);
61727
- links.resolvedType = getIntersectionType(ts.map(node.types, getTypeFromTypeNode), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
61751
+ var types = ts.map(node.types, getTypeFromTypeNode);
61752
+ var noSupertypeReduction = types.length === 2 && !!(types[0].flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) && types[1] === emptyTypeLiteralType;
61753
+ links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction);
61728
61754
  }
61729
61755
  return links.resolvedType;
61730
61756
  }
@@ -64510,6 +64536,17 @@ var ts;
64510
64536
  return !!(ts.getObjectFlags(type) & 16 /* Anonymous */ && (type.members && isEmptyResolvedType(type) ||
64511
64537
  type.symbol && type.symbol.flags & 2048 /* TypeLiteral */ && getMembersOfSymbol(type.symbol).size === 0));
64512
64538
  }
64539
+ function isUnknownLikeUnionType(type) {
64540
+ if (strictNullChecks && type.flags & 1048576 /* Union */) {
64541
+ if (!(type.objectFlags & 33554432 /* IsUnknownLikeUnionComputed */)) {
64542
+ var types = type.types;
64543
+ type.objectFlags |= 33554432 /* IsUnknownLikeUnionComputed */ | (types.length >= 3 && types[0].flags & 32768 /* Undefined */ &&
64544
+ types[1].flags & 65536 /* Null */ && ts.some(types, isEmptyAnonymousObjectType) ? 67108864 /* IsUnknownLikeUnion */ : 0);
64545
+ }
64546
+ return !!(type.objectFlags & 67108864 /* IsUnknownLikeUnion */);
64547
+ }
64548
+ return false;
64549
+ }
64513
64550
  function isStringIndexSignatureOnlyType(type) {
64514
64551
  return type.flags & 524288 /* Object */ && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfosOfType(type).length === 1 && !!getIndexInfoOfType(type, stringType) ||
64515
64552
  type.flags & 3145728 /* UnionOrIntersection */ && ts.every(type.types, isStringIndexSignatureOnlyType) ||
@@ -64589,7 +64626,7 @@ var ts;
64589
64626
  return true;
64590
64627
  if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
64591
64628
  return true;
64592
- if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
64629
+ if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */ && !(relation === strictSubtypeRelation && isEmptyAnonymousObjectType(source)))
64593
64630
  return true;
64594
64631
  if (relation === assignableRelation || relation === comparableRelation) {
64595
64632
  if (s & 1 /* Any */)
@@ -64599,6 +64636,9 @@ var ts;
64599
64636
  // bit-flag enum types sometimes look like literal enum types with numeric literal values.
64600
64637
  if (s & (8 /* Number */ | 256 /* NumberLiteral */) && !(s & 1024 /* EnumLiteral */) && (t & 32 /* Enum */ || relation === assignableRelation && t & 256 /* NumberLiteral */ && t & 1024 /* EnumLiteral */))
64601
64638
  return true;
64639
+ // Anything is assignable to a union containing undefined, null, and {}
64640
+ if (isUnknownLikeUnionType(target))
64641
+ return true;
64602
64642
  }
64603
64643
  return false;
64604
64644
  }
@@ -64641,16 +64681,27 @@ var ts;
64641
64681
  function getNormalizedType(type, writing) {
64642
64682
  while (true) {
64643
64683
  var t = isFreshLiteralType(type) ? type.regularType :
64644
- ts.getObjectFlags(type) & 4 /* Reference */ && type.node ? createTypeReference(type.target, getTypeArguments(type)) :
64645
- type.flags & 3145728 /* UnionOrIntersection */ ? getReducedType(type) :
64684
+ ts.getObjectFlags(type) & 4 /* Reference */ ? type.node ? createTypeReference(type.target, getTypeArguments(type)) : getSingleBaseForNonAugmentingSubtype(type) || type :
64685
+ type.flags & 3145728 /* UnionOrIntersection */ ? getNormalizedUnionOrIntersectionType(type, writing) :
64646
64686
  type.flags & 33554432 /* Substitution */ ? writing ? type.baseType : type.substitute :
64647
64687
  type.flags & 25165824 /* Simplifiable */ ? getSimplifiedType(type, writing) :
64648
64688
  type;
64649
- t = getSingleBaseForNonAugmentingSubtype(t) || t;
64650
64689
  if (t === type)
64651
- break;
64690
+ return t;
64652
64691
  type = t;
64653
64692
  }
64693
+ }
64694
+ function getNormalizedUnionOrIntersectionType(type, writing) {
64695
+ var reduced = getReducedType(type);
64696
+ if (reduced !== type) {
64697
+ return reduced;
64698
+ }
64699
+ if (type.flags & 2097152 /* Intersection */) {
64700
+ var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); });
64701
+ if (normalizedTypes !== type.types) {
64702
+ return getIntersectionType(normalizedTypes);
64703
+ }
64704
+ }
64654
64705
  return type;
64655
64706
  }
64656
64707
  /**
@@ -65097,6 +65148,7 @@ var ts;
65097
65148
  return 0 /* False */;
65098
65149
  }
65099
65150
  function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
65151
+ var _a, _b;
65100
65152
  var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
65101
65153
  var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
65102
65154
  source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
@@ -65137,6 +65189,9 @@ var ts;
65137
65189
  return;
65138
65190
  }
65139
65191
  reportRelationError(headMessage, source, target);
65192
+ 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 */))) {
65193
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
65194
+ }
65140
65195
  }
65141
65196
  function traceUnionsOrIntersectionsTooLarge(source, target) {
65142
65197
  if (!ts.tracing) {
@@ -65923,13 +65978,6 @@ var ts;
65923
65978
  // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
65924
65979
  if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
65925
65980
  var constraint = getConstraintOfType(source) || unknownType;
65926
- if (!getConstraintOfType(source) || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
65927
- // A type variable with no constraint is not related to the non-primitive object type.
65928
- if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
65929
- resetErrorInfo(saveErrorInfo);
65930
- return result;
65931
- }
65932
- }
65933
65981
  // 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
65934
65982
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
65935
65983
  resetErrorInfo(saveErrorInfo);
@@ -67403,9 +67451,11 @@ var ts;
67403
67451
  return getSupertypeOrUnion(types);
67404
67452
  }
67405
67453
  var primaryTypes = ts.filter(types, function (t) { return !(t.flags & 98304 /* Nullable */); });
67406
- return primaryTypes.length ?
67407
- getNullableType(getSupertypeOrUnion(primaryTypes), getFalsyFlagsOfTypes(types) & 98304 /* Nullable */) :
67408
- getUnionType(types, 2 /* Subtype */);
67454
+ if (primaryTypes.length) {
67455
+ var supertypeOrUnion = getSupertypeOrUnion(primaryTypes);
67456
+ return primaryTypes === types ? supertypeOrUnion : getUnionType(__spreadArray([supertypeOrUnion], ts.filter(types, function (t) { return !!(t.flags & 98304 /* Nullable */); }), true));
67457
+ }
67458
+ return getUnionType(types, 2 /* Subtype */);
67409
67459
  }
67410
67460
  // Return the leftmost type for which no type to the right is a subtype.
67411
67461
  function getCommonSubtype(types) {
@@ -67604,12 +67654,13 @@ var ts;
67604
67654
  // flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
67605
67655
  // no flags for all other types (including non-falsy literal types).
67606
67656
  function getFalsyFlags(type) {
67607
- return type.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(type.types) :
67608
- type.flags & 128 /* StringLiteral */ ? type.value === "" ? 128 /* StringLiteral */ : 0 :
67609
- type.flags & 256 /* NumberLiteral */ ? type.value === 0 ? 256 /* NumberLiteral */ : 0 :
67610
- type.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(type) ? 2048 /* BigIntLiteral */ : 0 :
67611
- type.flags & 512 /* BooleanLiteral */ ? (type === falseType || type === regularFalseType) ? 512 /* BooleanLiteral */ : 0 :
67612
- type.flags & 117724 /* PossiblyFalsy */;
67657
+ var t = type.flags & 2097152 /* Intersection */ ? getBaseConstraintOrType(type) : type;
67658
+ return t.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(t.types) :
67659
+ t.flags & 128 /* StringLiteral */ ? t.value === "" ? 128 /* StringLiteral */ : 0 :
67660
+ t.flags & 256 /* NumberLiteral */ ? t.value === 0 ? 256 /* NumberLiteral */ : 0 :
67661
+ t.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(t) ? 2048 /* BigIntLiteral */ : 0 :
67662
+ t.flags & 512 /* BooleanLiteral */ ? (t === falseType || t === regularFalseType) ? 512 /* BooleanLiteral */ : 0 :
67663
+ t.flags & 117724 /* PossiblyFalsy */;
67613
67664
  }
67614
67665
  function removeDefinitelyFalsyTypes(type) {
67615
67666
  return getFalsyFlags(type) & 117632 /* DefinitelyFalsy */ ?
@@ -67649,20 +67700,22 @@ var ts;
67649
67700
  return type.flags & 32768 /* Undefined */ ? type : getUnionType([type, isProperty ? missingType : undefinedType]);
67650
67701
  }
67651
67702
  function getGlobalNonNullableTypeInstantiation(type) {
67652
- // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67653
- // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67654
- // that isn't eliminated by a NonNullable<T> instantiation.
67655
- var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67656
67703
  if (!deferredGlobalNonNullableTypeAlias) {
67657
67704
  deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable", 524288 /* TypeAlias */, /*diagnostic*/ undefined) || unknownSymbol;
67658
67705
  }
67659
- // If the NonNullable<T> type is available, return an instantiation. Otherwise just return the reduced type.
67660
67706
  return deferredGlobalNonNullableTypeAlias !== unknownSymbol ?
67661
- getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [reducedType]) :
67662
- reducedType;
67707
+ getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]) :
67708
+ getIntersectionType([type, emptyObjectType]);
67663
67709
  }
67664
67710
  function getNonNullableType(type) {
67665
- return strictNullChecks ? getGlobalNonNullableTypeInstantiation(type) : type;
67711
+ if (strictNullChecks) {
67712
+ // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67713
+ // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67714
+ // that isn't eliminated by a NonNullable<T> instantiation.
67715
+ var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67716
+ return maybeTypeOfKind(reducedType, 465829888 /* Instantiable */) ? getGlobalNonNullableTypeInstantiation(reducedType) : reducedType;
67717
+ }
67718
+ return type;
67666
67719
  }
67667
67720
  function addOptionalTypeMarker(type) {
67668
67721
  return strictNullChecks ? getUnionType([type, optionalType]) : type;
@@ -68343,13 +68396,40 @@ var ts;
68343
68396
  return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
68344
68397
  sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
68345
68398
  }
68346
- function isValidBigIntString(s) {
68399
+ /**
68400
+ * Tests whether the provided string can be parsed as a number.
68401
+ * @param s The string to test.
68402
+ * @param roundTripOnly Indicates the resulting number matches the input when converted back to a string.
68403
+ */
68404
+ function isValidNumberString(s, roundTripOnly) {
68405
+ if (s === "")
68406
+ return false;
68407
+ var n = +s;
68408
+ return isFinite(n) && (!roundTripOnly || "" + n === s);
68409
+ }
68410
+ /**
68411
+ * @param text a valid bigint string excluding a trailing `n`, but including a possible prefix `-`. Use `isValidBigIntString(text, roundTripOnly)` before calling this function.
68412
+ */
68413
+ function parseBigIntLiteralType(text) {
68414
+ var negative = text.startsWith("-");
68415
+ var base10Value = ts.parsePseudoBigInt((negative ? text.slice(1) : text) + "n");
68416
+ return getBigIntLiteralType({ negative: negative, base10Value: base10Value });
68417
+ }
68418
+ /**
68419
+ * Tests whether the provided string can be parsed as a bigint.
68420
+ * @param s The string to test.
68421
+ * @param roundTripOnly Indicates the resulting bigint matches the input when converted back to a string.
68422
+ */
68423
+ function isValidBigIntString(s, roundTripOnly) {
68424
+ if (s === "")
68425
+ return false;
68347
68426
  var scanner = ts.createScanner(99 /* ESNext */, /*skipTrivia*/ false);
68348
68427
  var success = true;
68349
68428
  scanner.setOnError(function () { return success = false; });
68350
68429
  scanner.setText(s + "n");
68351
68430
  var result = scanner.scan();
68352
- if (result === 40 /* MinusToken */) {
68431
+ var negative = result === 40 /* MinusToken */;
68432
+ if (negative) {
68353
68433
  result = scanner.scan();
68354
68434
  }
68355
68435
  var flags = scanner.getTokenFlags();
@@ -68358,7 +68438,8 @@ var ts;
68358
68438
  // * a bigint can be scanned, and that when it is scanned, it is
68359
68439
  // * the full length of the input string (so the scanner is one character beyond the augmented input length)
68360
68440
  // * it does not contain a numeric seperator (the `BigInt` constructor does not accept a numeric seperator in its input)
68361
- return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */);
68441
+ return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */)
68442
+ && (!roundTripOnly || s === ts.pseudoBigIntToString({ negative: negative, base10Value: ts.parsePseudoBigInt(scanner.getTokenValue()) }));
68362
68443
  }
68363
68444
  function isValidTypeForTemplateLiteralPlaceholder(source, target) {
68364
68445
  if (source === target || target.flags & (1 /* Any */ | 4 /* String */)) {
@@ -68366,8 +68447,8 @@ var ts;
68366
68447
  }
68367
68448
  if (source.flags & 128 /* StringLiteral */) {
68368
68449
  var value = source.value;
68369
- return !!(target.flags & 8 /* Number */ && value !== "" && isFinite(+value) ||
68370
- target.flags & 64 /* BigInt */ && value !== "" && isValidBigIntString(value) ||
68450
+ return !!(target.flags & 8 /* Number */ && isValidNumberString(value, /*roundTripOnly*/ false) ||
68451
+ target.flags & 64 /* BigInt */ && isValidBigIntString(value, /*roundTripOnly*/ false) ||
68371
68452
  target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName);
68372
68453
  }
68373
68454
  if (source.flags & 134217728 /* TemplateLiteral */) {
@@ -68940,8 +69021,57 @@ var ts;
68940
69021
  // upon instantiation, would collapse all the placeholders to just 'string', and an assignment check might
68941
69022
  // succeed. That would be a pointless and confusing outcome.
68942
69023
  if (matches || ts.every(target.texts, function (s) { return s.length === 0; })) {
69024
+ var _loop_23 = function (i) {
69025
+ var source_1 = matches ? matches[i] : neverType;
69026
+ var target_3 = types[i];
69027
+ // If we are inferring from a string literal type to a type variable whose constraint includes one of the
69028
+ // allowed template literal placeholder types, infer from a literal type corresponding to the constraint.
69029
+ if (source_1.flags & 128 /* StringLiteral */ && target_3.flags & 8650752 /* TypeVariable */) {
69030
+ var inferenceContext = getInferenceInfoForType(target_3);
69031
+ var constraint = inferenceContext ? getBaseConstraintOfType(inferenceContext.typeParameter) : undefined;
69032
+ if (constraint && !isTypeAny(constraint)) {
69033
+ var constraintTypes = constraint.flags & 1048576 /* Union */ ? constraint.types : [constraint];
69034
+ var allTypeFlags_1 = ts.reduceLeft(constraintTypes, function (flags, t) { return flags | t.flags; }, 0);
69035
+ // If the constraint contains `string`, we don't need to look for a more preferred type
69036
+ if (!(allTypeFlags_1 & 4 /* String */)) {
69037
+ var str_1 = source_1.value;
69038
+ // If the type contains `number` or a number literal and the string isn't a valid number, exclude numbers
69039
+ if (allTypeFlags_1 & 296 /* NumberLike */ && !isValidNumberString(str_1, /*roundTripOnly*/ true)) {
69040
+ allTypeFlags_1 &= ~296 /* NumberLike */;
69041
+ }
69042
+ // If the type contains `bigint` or a bigint literal and the string isn't a valid bigint, exclude bigints
69043
+ if (allTypeFlags_1 & 2112 /* BigIntLike */ && !isValidBigIntString(str_1, /*roundTripOnly*/ true)) {
69044
+ allTypeFlags_1 &= ~2112 /* BigIntLike */;
69045
+ }
69046
+ // for each type in the constraint, find the highest priority matching type
69047
+ var matchingType = ts.reduceLeft(constraintTypes, function (left, right) {
69048
+ return !(right.flags & allTypeFlags_1) ? left :
69049
+ left.flags & 4 /* String */ ? left : right.flags & 4 /* String */ ? source_1 :
69050
+ left.flags & 134217728 /* TemplateLiteral */ ? left : right.flags & 134217728 /* TemplateLiteral */ && isTypeMatchedByTemplateLiteralType(source_1, right) ? source_1 :
69051
+ left.flags & 268435456 /* StringMapping */ ? left : right.flags & 268435456 /* StringMapping */ && str_1 === applyStringMapping(right.symbol, str_1) ? source_1 :
69052
+ left.flags & 128 /* StringLiteral */ ? left : right.flags & 128 /* StringLiteral */ && right.value === str_1 ? right :
69053
+ left.flags & 8 /* Number */ ? left : right.flags & 8 /* Number */ ? getNumberLiteralType(+str_1) :
69054
+ left.flags & 32 /* Enum */ ? left : right.flags & 32 /* Enum */ ? getNumberLiteralType(+str_1) :
69055
+ left.flags & 256 /* NumberLiteral */ ? left : right.flags & 256 /* NumberLiteral */ && right.value === +str_1 ? right :
69056
+ left.flags & 64 /* BigInt */ ? left : right.flags & 64 /* BigInt */ ? parseBigIntLiteralType(str_1) :
69057
+ left.flags & 2048 /* BigIntLiteral */ ? left : right.flags & 2048 /* BigIntLiteral */ && ts.pseudoBigIntToString(right.value) === str_1 ? right :
69058
+ left.flags & 16 /* Boolean */ ? left : right.flags & 16 /* Boolean */ ? str_1 === "true" ? trueType : str_1 === "false" ? falseType : booleanType :
69059
+ left.flags & 512 /* BooleanLiteral */ ? left : right.flags & 512 /* BooleanLiteral */ && right.intrinsicName === str_1 ? right :
69060
+ left.flags & 32768 /* Undefined */ ? left : right.flags & 32768 /* Undefined */ && right.intrinsicName === str_1 ? right :
69061
+ left.flags & 65536 /* Null */ ? left : right.flags & 65536 /* Null */ && right.intrinsicName === str_1 ? right :
69062
+ left;
69063
+ }, neverType);
69064
+ if (!(matchingType.flags & 131072 /* Never */)) {
69065
+ inferFromTypes(matchingType, target_3);
69066
+ return "continue";
69067
+ }
69068
+ }
69069
+ }
69070
+ }
69071
+ inferFromTypes(source_1, target_3);
69072
+ };
68943
69073
  for (var i = 0; i < types.length; i++) {
68944
- inferFromTypes(matches ? matches[i] : neverType, types[i]);
69074
+ _loop_23(i);
68945
69075
  }
68946
69076
  }
68947
69077
  }
@@ -69459,7 +69589,7 @@ var ts;
69459
69589
  function mapTypesByKeyProperty(types, name) {
69460
69590
  var map = new ts.Map();
69461
69591
  var count = 0;
69462
- var _loop_23 = function (type) {
69592
+ var _loop_24 = function (type) {
69463
69593
  if (type.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 58982400 /* InstantiableNonPrimitive */)) {
69464
69594
  var discriminant = getTypeOfPropertyOfType(type, name);
69465
69595
  if (discriminant) {
@@ -69485,7 +69615,7 @@ var ts;
69485
69615
  };
69486
69616
  for (var _i = 0, types_16 = types; _i < types_16.length; _i++) {
69487
69617
  var type = types_16[_i];
69488
- var state_9 = _loop_23(type);
69618
+ var state_9 = _loop_24(type);
69489
69619
  if (typeof state_9 === "object")
69490
69620
  return state_9.value;
69491
69621
  }
@@ -69693,6 +69823,24 @@ var ts;
69693
69823
  function getTypeWithFacts(type, include) {
69694
69824
  return filterType(type, function (t) { return (getTypeFacts(t) & include) !== 0; });
69695
69825
  }
69826
+ function getIntersectionWithFacts(type, facts) {
69827
+ var reduced = recombineUnknownType(getTypeWithFacts(strictNullChecks && type.flags & 2 /* Unknown */ ? unknownUnionType : type, facts));
69828
+ if (strictNullChecks) {
69829
+ switch (facts) {
69830
+ case 524288 /* NEUndefined */:
69831
+ 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; });
69832
+ case 1048576 /* NENull */:
69833
+ 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; });
69834
+ case 2097152 /* NEUndefinedOrNull */:
69835
+ case 4194304 /* Truthy */:
69836
+ return mapType(reduced, function (t) { return getTypeFacts(t) & 262144 /* EQUndefinedOrNull */ ? getGlobalNonNullableTypeInstantiation(t) : t; });
69837
+ }
69838
+ }
69839
+ return reduced;
69840
+ }
69841
+ function recombineUnknownType(type) {
69842
+ return type === unknownUnionType ? unknownType : type;
69843
+ }
69696
69844
  function getTypeWithDefault(type, defaultExpression) {
69697
69845
  return defaultExpression ?
69698
69846
  getUnionType([getNonUndefinedType(type), getTypeOfExpression(defaultExpression)]) :
@@ -70750,7 +70898,7 @@ var ts;
70750
70898
  if (isEvolvingArrayTypeList(types)) {
70751
70899
  return getEvolvingArrayType(getUnionType(ts.map(types, getElementTypeOfEvolvingArrayType)));
70752
70900
  }
70753
- var result = getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction);
70901
+ var result = recombineUnknownType(getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction));
70754
70902
  if (result !== declaredType && result.flags & declaredType.flags & 1048576 /* Union */ && ts.arraysEqual(result.types, declaredType.types)) {
70755
70903
  return declaredType;
70756
70904
  }
@@ -70852,8 +71000,7 @@ var ts;
70852
71000
  }
70853
71001
  function narrowTypeByTruthiness(type, expr, assumeTrue) {
70854
71002
  if (isMatchingReference(reference, expr)) {
70855
- return type.flags & 2 /* Unknown */ && assumeTrue ? nonNullUnknownType :
70856
- getTypeWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
71003
+ return getIntersectionWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70857
71004
  }
70858
71005
  if (strictNullChecks && assumeTrue && optionalChainContainsReference(expr, reference)) {
70859
71006
  type = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
@@ -71006,9 +71153,6 @@ var ts;
71006
71153
  assumeTrue = !assumeTrue;
71007
71154
  }
71008
71155
  var valueType = getTypeOfExpression(value);
71009
- if (assumeTrue && (type.flags & 2 /* Unknown */) && (operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */) && (valueType.flags & 65536 /* Null */)) {
71010
- return getUnionType([nullType, undefinedType]);
71011
- }
71012
71156
  if ((type.flags & 2 /* Unknown */) && assumeTrue && (operator === 36 /* EqualsEqualsEqualsToken */ || operator === 37 /* ExclamationEqualsEqualsToken */)) {
71013
71157
  if (valueType.flags & (131068 /* Primitive */ | 67108864 /* NonPrimitive */)) {
71014
71158
  return valueType;
@@ -71028,7 +71172,7 @@ var ts;
71028
71172
  valueType.flags & 65536 /* Null */ ?
71029
71173
  assumeTrue ? 131072 /* EQNull */ : 1048576 /* NENull */ :
71030
71174
  assumeTrue ? 65536 /* EQUndefined */ : 524288 /* NEUndefined */;
71031
- return type.flags & 2 /* Unknown */ && facts & (1048576 /* NENull */ | 2097152 /* NEUndefinedOrNull */) ? nonNullUnknownType : getTypeWithFacts(type, facts);
71175
+ return getIntersectionWithFacts(type, facts);
71032
71176
  }
71033
71177
  if (assumeTrue) {
71034
71178
  var filterFn = operator === 34 /* EqualsEqualsToken */ ?
@@ -71056,17 +71200,11 @@ var ts;
71056
71200
  if (type.flags & 1 /* Any */ && literal.text === "function") {
71057
71201
  return type;
71058
71202
  }
71059
- if (assumeTrue && type.flags & 2 /* Unknown */ && literal.text === "object") {
71060
- // The non-null unknown type is used to track whether a previous narrowing operation has removed the null type
71061
- // from the unknown type. For example, the expression `x && typeof x === 'object'` first narrows x to the non-null
71062
- // unknown type, and then narrows that to the non-primitive type.
71063
- return type === nonNullUnknownType ? nonPrimitiveType : getUnionType([nonPrimitiveType, nullType]);
71064
- }
71065
71203
  var facts = assumeTrue ?
71066
71204
  typeofEQFacts.get(literal.text) || 128 /* TypeofEQHostObject */ :
71067
71205
  typeofNEFacts.get(literal.text) || 32768 /* TypeofNEHostObject */;
71068
71206
  var impliedType = getImpliedTypeFromTypeofGuard(type, literal.text);
71069
- return getTypeWithFacts(assumeTrue && impliedType ? mapType(type, narrowUnionMemberByTypeof(impliedType)) : type, facts);
71207
+ return getTypeWithFacts(assumeTrue && impliedType ? narrowTypeByImpliedType(type, impliedType) : type, facts);
71070
71208
  }
71071
71209
  function narrowTypeBySwitchOptionalChainContainment(type, switchStatement, clauseStart, clauseEnd, clauseCheck) {
71072
71210
  var everyClauseChecks = clauseStart !== clauseEnd && ts.every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), clauseCheck);
@@ -71115,10 +71253,10 @@ var ts;
71115
71253
  }
71116
71254
  function getImpliedTypeFromTypeofGuard(type, text) {
71117
71255
  switch (text) {
71256
+ case "object":
71257
+ return type.flags & 1 /* Any */ ? type : getUnionType([nullType, nonPrimitiveType]);
71118
71258
  case "function":
71119
71259
  return type.flags & 1 /* Any */ ? type : globalFunctionType;
71120
- case "object":
71121
- return type.flags & 2 /* Unknown */ ? getUnionType([nonPrimitiveType, nullType]) : type;
71122
71260
  default:
71123
71261
  return typeofTypesByName.get(text);
71124
71262
  }
@@ -71129,22 +71267,27 @@ var ts;
71129
71267
  // the guard. For example: narrowing `{} | undefined` by `"boolean"` should produce the type `boolean`, not
71130
71268
  // the filtered type `{}`. For this reason we narrow constituents of the union individually, in addition to
71131
71269
  // filtering by type-facts.
71132
- function narrowUnionMemberByTypeof(candidate) {
71133
- return function (type) {
71134
- if (isTypeSubtypeOf(type, candidate)) {
71135
- return type;
71136
- }
71137
- if (isTypeSubtypeOf(candidate, type)) {
71138
- return candidate;
71270
+ function narrowTypeByImpliedType(type, candidate) {
71271
+ if (type.flags & 3 /* AnyOrUnknown */) {
71272
+ return candidate;
71273
+ }
71274
+ return mapType(type, function (t) {
71275
+ if (isTypeRelatedTo(t, candidate, strictSubtypeRelation)) {
71276
+ return t;
71139
71277
  }
71140
- if (type.flags & 465829888 /* Instantiable */) {
71141
- var constraint = getBaseConstraintOfType(type) || anyType;
71142
- if (isTypeSubtypeOf(candidate, constraint)) {
71143
- return getIntersectionType([type, candidate]);
71278
+ return mapType(candidate, function (c) {
71279
+ if (!areTypesComparable(t, c)) {
71280
+ return neverType;
71144
71281
  }
71145
- }
71146
- return type;
71147
- };
71282
+ if (c.flags & 131068 /* Primitive */ && t.flags & 524288 /* Object */ && !isEmptyAnonymousObjectType(t)) {
71283
+ return isTypeSubtypeOf(c, t) ? c : neverType;
71284
+ }
71285
+ if (c === globalFunctionType && isTypeSubtypeOf(c, t)) {
71286
+ return c;
71287
+ }
71288
+ return getIntersectionType([t, c]);
71289
+ });
71290
+ });
71148
71291
  }
71149
71292
  function narrowBySwitchOnTypeOf(type, switchStatement, clauseStart, clauseEnd) {
71150
71293
  var switchWitnesses = getSwitchClauseTypeOfWitnesses(switchStatement, /*retainDefault*/ true);
@@ -71203,7 +71346,7 @@ var ts;
71203
71346
  because it is caught in the first clause.
71204
71347
  */
71205
71348
  var impliedType = getTypeWithFacts(getUnionType(clauseWitnesses.map(function (text) { return getImpliedTypeFromTypeofGuard(type, text) || type; })), switchFacts);
71206
- return getTypeWithFacts(mapType(type, narrowUnionMemberByTypeof(impliedType)), switchFacts);
71349
+ return getTypeWithFacts(narrowTypeByImpliedType(type, impliedType), switchFacts);
71207
71350
  }
71208
71351
  function isMatchingConstructorReference(expr) {
71209
71352
  return (ts.isPropertyAccessExpression(expr) && ts.idText(expr.name) === "constructor" ||
@@ -71507,7 +71650,9 @@ var ts;
71507
71650
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
71508
71651
  }
71509
71652
  function isGenericTypeWithUnionConstraint(type) {
71510
- return !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71653
+ return type.flags & 2097152 /* Intersection */ ?
71654
+ ts.some(type.types, isGenericTypeWithUnionConstraint) :
71655
+ !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71511
71656
  }
71512
71657
  function isGenericTypeWithoutNullableConstraint(type) {
71513
71658
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
@@ -71535,7 +71680,7 @@ var ts;
71535
71680
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
71536
71681
  someType(type, isGenericTypeWithUnionConstraint) &&
71537
71682
  (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
71538
- return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ ? getBaseConstraintOrType(t) : t; }) : type;
71683
+ return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
71539
71684
  }
71540
71685
  function isExportOrExportExpression(location) {
71541
71686
  return !!ts.findAncestor(location, function (n) {
@@ -75873,7 +76018,7 @@ var ts;
75873
76018
  if (spreadIndex >= 0) {
75874
76019
  // Create synthetic arguments from spreads of tuple types.
75875
76020
  var effectiveArgs_1 = args.slice(0, spreadIndex);
75876
- var _loop_24 = function (i) {
76021
+ var _loop_25 = function (i) {
75877
76022
  var arg = args[i];
75878
76023
  // We can call checkExpressionCached because spread expressions never have a contextual type.
75879
76024
  var spreadType = arg.kind === 225 /* SpreadElement */ && (flowLoopCount ? checkExpression(arg.expression) : checkExpressionCached(arg.expression));
@@ -75890,7 +76035,7 @@ var ts;
75890
76035
  }
75891
76036
  };
75892
76037
  for (var i = spreadIndex; i < args.length; i++) {
75893
- _loop_24(i);
76038
+ _loop_25(i);
75894
76039
  }
75895
76040
  return effectiveArgs_1;
75896
76041
  }
@@ -76210,7 +76355,7 @@ var ts;
76210
76355
  var min_3 = Number.MAX_VALUE;
76211
76356
  var minIndex = 0;
76212
76357
  var i_1 = 0;
76213
- var _loop_25 = function (c) {
76358
+ var _loop_26 = function (c) {
76214
76359
  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)); };
76215
76360
  var diags_2 = getSignatureApplicabilityError(node, args, c, assignableRelation, 0 /* Normal */, /*reportErrors*/ true, chain_2);
76216
76361
  if (diags_2) {
@@ -76228,7 +76373,7 @@ var ts;
76228
76373
  };
76229
76374
  for (var _a = 0, candidatesForArgumentError_1 = candidatesForArgumentError; _a < candidatesForArgumentError_1.length; _a++) {
76230
76375
  var c = candidatesForArgumentError_1[_a];
76231
- _loop_25(c);
76376
+ _loop_26(c);
76232
76377
  }
76233
76378
  var diags_3 = max > 1 ? allDiagnostics[minIndex] : ts.flatten(allDiagnostics);
76234
76379
  ts.Debug.assert(diags_3.length > 0, "No errors reported for 3 or fewer overload signatures");
@@ -76386,7 +76531,7 @@ var ts;
76386
76531
  }
76387
76532
  var _a = ts.minAndMax(candidates, getNumNonRestParameters), minArgumentCount = _a.min, maxNonRestParam = _a.max;
76388
76533
  var parameters = [];
76389
- var _loop_26 = function (i) {
76534
+ var _loop_27 = function (i) {
76390
76535
  var symbols = ts.mapDefined(candidates, function (s) { return signatureHasRestParameter(s) ?
76391
76536
  i < s.parameters.length - 1 ? s.parameters[i] : ts.last(s.parameters) :
76392
76537
  i < s.parameters.length ? s.parameters[i] : undefined; });
@@ -76394,7 +76539,7 @@ var ts;
76394
76539
  parameters.push(createCombinedSymbolFromTypes(symbols, ts.mapDefined(candidates, function (candidate) { return tryGetTypeAtPosition(candidate, i); })));
76395
76540
  };
76396
76541
  for (var i = 0; i < maxNonRestParam; i++) {
76397
- _loop_26(i);
76542
+ _loop_27(i);
76398
76543
  }
76399
76544
  var restParameterSymbols = ts.mapDefined(candidates, function (c) { return signatureHasRestParameter(c) ? ts.last(c.parameters) : undefined; });
76400
76545
  var flags = 0 /* None */;
@@ -80451,7 +80596,7 @@ var ts;
80451
80596
  var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
80452
80597
  if (indexSymbol === null || indexSymbol === void 0 ? void 0 : indexSymbol.declarations) {
80453
80598
  var indexSignatureMap_1 = new ts.Map();
80454
- var _loop_27 = function (declaration) {
80599
+ var _loop_28 = function (declaration) {
80455
80600
  if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
80456
80601
  forEachType(getTypeFromTypeNode(declaration.parameters[0].type), function (type) {
80457
80602
  var entry = indexSignatureMap_1.get(getTypeId(type));
@@ -80466,7 +80611,7 @@ var ts;
80466
80611
  };
80467
80612
  for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
80468
80613
  var declaration = _a[_i];
80469
- _loop_27(declaration);
80614
+ _loop_28(declaration);
80470
80615
  }
80471
80616
  indexSignatureMap_1.forEach(function (entry) {
80472
80617
  if (entry.declarations.length > 1) {
@@ -82662,7 +82807,7 @@ var ts;
82662
82807
  }
82663
82808
  // For a commonjs `const x = require`, validate the alias and exit
82664
82809
  var symbol = getSymbolOfNode(node);
82665
- if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
82810
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* BindingElement */ ? node.parent.parent : node)) {
82666
82811
  checkAliasSymbol(node);
82667
82812
  return;
82668
82813
  }
@@ -83927,7 +84072,7 @@ var ts;
83927
84072
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83928
84073
  var localPropDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
83929
84074
  name && name.kind === 162 /* ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
83930
- var _loop_28 = function (info) {
84075
+ var _loop_29 = function (info) {
83931
84076
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
83932
84077
  // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
83933
84078
  // in the containing type, or (c) the containing type is an interface and no base interface contains both the property and
@@ -83940,7 +84085,7 @@ var ts;
83940
84085
  };
83941
84086
  for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
83942
84087
  var info = indexInfos_9[_i];
83943
- _loop_28(info);
84088
+ _loop_29(info);
83944
84089
  }
83945
84090
  }
83946
84091
  function checkIndexConstraintForIndexSignature(type, checkInfo) {
@@ -83948,7 +84093,7 @@ var ts;
83948
84093
  var indexInfos = getApplicableIndexInfos(type, checkInfo.keyType);
83949
84094
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83950
84095
  var localCheckDeclaration = declaration && getParentOfSymbol(getSymbolOfNode(declaration)) === type.symbol ? declaration : undefined;
83951
- var _loop_29 = function (info) {
84096
+ var _loop_30 = function (info) {
83952
84097
  if (info === checkInfo)
83953
84098
  return "continue";
83954
84099
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
@@ -83963,7 +84108,7 @@ var ts;
83963
84108
  };
83964
84109
  for (var _i = 0, indexInfos_10 = indexInfos; _i < indexInfos_10.length; _i++) {
83965
84110
  var info = indexInfos_10[_i];
83966
- _loop_29(info);
84111
+ _loop_30(info);
83967
84112
  }
83968
84113
  }
83969
84114
  function checkTypeNameIsReserved(name, message) {
@@ -84282,7 +84427,7 @@ var ts;
84282
84427
  var baseTypes = baseTypeNode && getBaseTypes(type);
84283
84428
  var baseWithThis = (baseTypes === null || baseTypes === void 0 ? void 0 : baseTypes.length) ? getTypeWithThisArgument(ts.first(baseTypes), type.thisType) : undefined;
84284
84429
  var baseStaticType = getBaseConstructorTypeOfClass(type);
84285
- var _loop_30 = function (member) {
84430
+ var _loop_31 = function (member) {
84286
84431
  if (ts.hasAmbientModifier(member)) {
84287
84432
  return "continue";
84288
84433
  }
@@ -84299,7 +84444,7 @@ var ts;
84299
84444
  };
84300
84445
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84301
84446
  var member = _a[_i];
84302
- _loop_30(member);
84447
+ _loop_31(member);
84303
84448
  }
84304
84449
  }
84305
84450
  /**
@@ -84387,7 +84532,7 @@ var ts;
84387
84532
  function issueMemberSpecificError(node, typeWithThis, baseWithThis, broadDiag) {
84388
84533
  // iterate over all implemented properties and issue errors on each one which isn't compatible, rather than the class as a whole, if possible
84389
84534
  var issuedMemberError = false;
84390
- var _loop_31 = function (member) {
84535
+ var _loop_32 = function (member) {
84391
84536
  if (ts.isStatic(member)) {
84392
84537
  return "continue";
84393
84538
  }
@@ -84406,7 +84551,7 @@ var ts;
84406
84551
  };
84407
84552
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84408
84553
  var member = _a[_i];
84409
- _loop_31(member);
84554
+ _loop_32(member);
84410
84555
  }
84411
84556
  if (!issuedMemberError) {
84412
84557
  // check again with diagnostics to generate a less-specific error
@@ -122374,7 +122519,7 @@ var ts;
122374
122519
  });
122375
122520
  // Sort by paths closest to importing file Name directory
122376
122521
  var sortedPaths = [];
122377
- var _loop_32 = function (directory) {
122522
+ var _loop_33 = function (directory) {
122378
122523
  var directoryStart = ts.ensureTrailingDirectorySeparator(directory);
122379
122524
  var pathsInDirectory;
122380
122525
  allFileNames.forEach(function (_a, fileName) {
@@ -122398,7 +122543,7 @@ var ts;
122398
122543
  };
122399
122544
  var out_directory_1;
122400
122545
  for (var directory = ts.getDirectoryPath(importingFileName); allFileNames.size !== 0;) {
122401
- var state_10 = _loop_32(directory);
122546
+ var state_10 = _loop_33(directory);
122402
122547
  directory = out_directory_1;
122403
122548
  if (state_10 === "break")
122404
122549
  break;
@@ -136943,7 +137088,7 @@ var ts;
136943
137088
  ts.Debug.assert(parent.name === node);
136944
137089
  return true;
136945
137090
  case 203 /* BindingElement */:
136946
- return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent);
137091
+ return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent.parent.parent);
136947
137092
  default:
136948
137093
  return false;
136949
137094
  }
@@ -138409,7 +138554,7 @@ var ts;
138409
138554
  // Use the parent symbol if the location is commonjs require syntax on javascript files only.
138410
138555
  if (ts.isInJSFile(referenceLocation)
138411
138556
  && referenceLocation.parent.kind === 203 /* BindingElement */
138412
- && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) {
138557
+ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent.parent.parent)) {
138413
138558
  referenceSymbol = referenceLocation.parent.symbol;
138414
138559
  // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In
138415
138560
  // this case, just skip it, since the bound identifiers are not an alias of the import.
@@ -147785,11 +147930,9 @@ var ts;
147785
147930
  if (listEndToken !== 0 /* Unknown */ && formattingScanner.isOnToken() && formattingScanner.getStartPos() < originalRange.end) {
147786
147931
  var tokenInfo = formattingScanner.readTokenInfo(parent);
147787
147932
  if (tokenInfo.token.kind === 27 /* CommaToken */ && ts.isCallLikeExpression(parent)) {
147788
- var commaTokenLine = sourceFile.getLineAndCharacterOfPosition(tokenInfo.token.pos).line;
147789
- if (startLine !== commaTokenLine) {
147790
- formattingScanner.advance();
147791
- tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
147792
- }
147933
+ // consume the comma
147934
+ consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
147935
+ tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
147793
147936
  }
147794
147937
  // consume the list end token only if it is still belong to the parent
147795
147938
  // there might be the case when current token matches end token but does not considered as one
@@ -175078,6 +175221,7 @@ var ts;
175078
175221
  return info && !info.isLocal ? { fileName: info.fileName, pos: info.textSpan.start } : undefined;
175079
175222
  }
175080
175223
  function getReferencesWorker(projects, defaultProject, initialLocation, logger) {
175224
+ var _a;
175081
175225
  var perProjectResults = getPerProjectReferences(projects, defaultProject, initialLocation,
175082
175226
  /*isForRename*/ false, function (project, position) {
175083
175227
  logger.info("Finding references to " + position.fileName + " position " + position.pos + " in project " + project.getProjectName());
@@ -175097,7 +175241,7 @@ var ts;
175097
175241
  // have started the other project searches from related symbols. Propagate the
175098
175242
  // correct results to all other projects.
175099
175243
  var defaultProjectResults = perProjectResults.get(defaultProject);
175100
- if (defaultProjectResults[0].references[0].isDefinition === undefined) {
175244
+ if (((_a = defaultProjectResults === null || defaultProjectResults === void 0 ? void 0 : defaultProjectResults[0].references[0]) === null || _a === void 0 ? void 0 : _a.isDefinition) === undefined) {
175101
175245
  // Clear all isDefinition properties
175102
175246
  perProjectResults.forEach(function (projectResults) {
175103
175247
  for (var _i = 0, projectResults_2 = projectResults; _i < projectResults_2.length; _i++) {
@@ -175114,8 +175258,8 @@ var ts;
175114
175258
  var knownSymbolSpans_1 = createDocumentSpanSet();
175115
175259
  for (var _i = 0, defaultProjectResults_1 = defaultProjectResults; _i < defaultProjectResults_1.length; _i++) {
175116
175260
  var referencedSymbol = defaultProjectResults_1[_i];
175117
- for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
175118
- var ref = _b[_a];
175261
+ for (var _b = 0, _c = referencedSymbol.references; _b < _c.length; _b++) {
175262
+ var ref = _c[_b];
175119
175263
  if (ref.isDefinition) {
175120
175264
  knownSymbolSpans_1.add(ref);
175121
175265
  // One is enough - updateIsDefinitionOfReferencedSymbols will fill out the set based on symbols
@@ -175275,11 +175419,9 @@ var ts;
175275
175419
  // it easier for the caller to skip post-processing.
175276
175420
  if (searchedProjects.size === 1) {
175277
175421
  var it = resultsMap.values().next();
175278
- ts.Debug.assert(!it.done);
175279
- return it.value;
175422
+ return it.done ? server.emptyArray : it.value; // There may not be any results at all
175280
175423
  }
175281
175424
  return resultsMap;
175282
- // May enqueue to otherPositionQueue
175283
175425
  function searchPosition(project, location) {
175284
175426
  var projectResults = getResultsForPosition(project, location);
175285
175427
  if (!projectResults)