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.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220526";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220529";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -5090,6 +5090,11 @@ var ts;
5090
5090
  // Flags that require TypeFlags.Union
5091
5091
  /* @internal */
5092
5092
  ObjectFlags[ObjectFlags["ContainsIntersections"] = 16777216] = "ContainsIntersections";
5093
+ /* @internal */
5094
+ ObjectFlags[ObjectFlags["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
5095
+ /* @internal */
5096
+ ObjectFlags[ObjectFlags["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
5097
+ /* @internal */
5093
5098
  // Flags that require TypeFlags.Intersection
5094
5099
  /* @internal */
5095
5100
  ObjectFlags[ObjectFlags["IsNeverIntersectionComputed"] = 16777216] = "IsNeverIntersectionComputed";
@@ -8403,6 +8408,7 @@ var ts;
8403
8408
  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),
8404
8409
  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."),
8405
8410
  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."),
8411
+ 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."),
8406
8412
  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."),
8407
8413
  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."),
8408
8414
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
@@ -16207,9 +16213,6 @@ var ts;
16207
16213
  }
16208
16214
  ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire;
16209
16215
  function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
16210
- if (node.kind === 203 /* BindingElement */) {
16211
- node = node.parent.parent;
16212
- }
16213
16216
  return ts.isVariableDeclaration(node) &&
16214
16217
  !!node.initializer &&
16215
16218
  isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true);
@@ -20021,8 +20024,9 @@ var ts;
20021
20024
  */
20022
20025
  function isFileForcedToBeModuleByFormat(file) {
20023
20026
  // Excludes declaration files - they still require an explicit `export {}` or the like
20024
- // for back compat purposes.
20025
- return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined;
20027
+ // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
20028
+ // that aren't esm-mode (meaning not in a `type: module` scope).
20029
+ return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) && !file.isDeclarationFile ? true : undefined;
20026
20030
  }
20027
20031
  function getSetExternalModuleIndicator(options) {
20028
20032
  // TODO: Should this callback be cached?
@@ -20030,7 +20034,7 @@ var ts;
20030
20034
  case ts.ModuleDetectionKind.Force:
20031
20035
  // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule
20032
20036
  return function (file) {
20033
- file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file);
20037
+ file.externalModuleIndicator = ts.isFileProbablyExternalModule(file) || !file.isDeclarationFile || undefined;
20034
20038
  };
20035
20039
  case ts.ModuleDetectionKind.Legacy:
20036
20040
  // Files are modules if they have imports, exports, or import.meta
@@ -20090,7 +20094,8 @@ var ts;
20090
20094
  }
20091
20095
  ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind;
20092
20096
  function getEmitModuleDetectionKind(options) {
20093
- return options.moduleDetection || ts.ModuleDetectionKind.Auto;
20097
+ return options.moduleDetection ||
20098
+ (getEmitModuleKind(options) === ts.ModuleKind.Node16 || getEmitModuleKind(options) === ts.ModuleKind.NodeNext ? ts.ModuleDetectionKind.Force : ts.ModuleDetectionKind.Auto);
20094
20099
  }
20095
20100
  ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind;
20096
20101
  function hasJsonModuleEmitEnabled(options) {
@@ -46935,12 +46940,14 @@ var ts;
46935
46940
  }
46936
46941
  }
46937
46942
  function setCommonJsModuleIndicator(node) {
46938
- if (file.externalModuleIndicator) {
46943
+ if (file.externalModuleIndicator && file.externalModuleIndicator !== true) {
46939
46944
  return false;
46940
46945
  }
46941
46946
  if (!file.commonJsModuleIndicator) {
46942
46947
  file.commonJsModuleIndicator = node;
46943
- bindSourceFileAsExternalModule();
46948
+ if (!file.externalModuleIndicator) {
46949
+ bindSourceFileAsExternalModule();
46950
+ }
46944
46951
  }
46945
46952
  return true;
46946
46953
  }
@@ -47354,7 +47361,11 @@ var ts;
47354
47361
  checkStrictModeEvalOrArguments(node, node.name);
47355
47362
  }
47356
47363
  if (!ts.isBindingPattern(node.name)) {
47357
- if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
47364
+ var possibleVariableDecl = node.kind === 254 /* VariableDeclaration */ ? node : node.parent.parent;
47365
+ if (ts.isInJSFile(node) &&
47366
+ ts.isVariableDeclarationInitializedToBareOrAccessedRequire(possibleVariableDecl) &&
47367
+ !ts.getJSDocTypeTag(node) &&
47368
+ !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
47358
47369
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
47359
47370
  }
47360
47371
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -48531,6 +48542,7 @@ var ts;
48531
48542
  var emptyTypeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type" /* Type */);
48532
48543
  emptyTypeLiteralSymbol.members = ts.createSymbolTable();
48533
48544
  var emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48545
+ var unknownUnionType = strictNullChecks ? getUnionType([undefinedType, nullType, createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray)]) : unknownType;
48534
48546
  var emptyGenericType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48535
48547
  emptyGenericType.instantiations = new ts.Map();
48536
48548
  var anyFunctionType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
@@ -50181,7 +50193,8 @@ var ts;
50181
50193
  && isAliasableOrJsExpression(node.parent.right)
50182
50194
  || node.kind === 297 /* ShorthandPropertyAssignment */
50183
50195
  || node.kind === 296 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
50184
- || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
50196
+ || node.kind === 254 /* VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)
50197
+ || node.kind === 203 /* BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent);
50185
50198
  }
50186
50199
  function isAliasableOrJsExpression(e) {
50187
50200
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50274,7 +50287,7 @@ var ts;
50274
50287
  return hasExportAssignmentSymbol(moduleSymbol);
50275
50288
  }
50276
50289
  // 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
50277
- return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias);
50290
+ return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias);
50278
50291
  }
50279
50292
  function getTargetOfImportClause(node, dontResolveAlias) {
50280
50293
  var _a;
@@ -58700,7 +58713,7 @@ var ts;
58700
58713
  }
58701
58714
  }
58702
58715
  }
58703
- else if (t.flags & 469892092 /* DisjointDomains */) {
58716
+ else if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58704
58717
  hasDisjointDomainType = true;
58705
58718
  }
58706
58719
  }
@@ -58712,7 +58725,7 @@ var ts;
58712
58725
  // intersection operation to reduce the union constraints.
58713
58726
  for (var _a = 0, types_6 = types; _a < types_6.length; _a++) {
58714
58727
  var t = types_6[_a];
58715
- if (t.flags & 469892092 /* DisjointDomains */) {
58728
+ if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58716
58729
  constraints = ts.append(constraints, t);
58717
58730
  }
58718
58731
  }
@@ -61261,7 +61274,7 @@ var ts;
61261
61274
  }
61262
61275
  return includes;
61263
61276
  }
61264
- function removeRedundantPrimitiveTypes(types, includes) {
61277
+ function removeRedundantSupertypes(types, includes) {
61265
61278
  var i = types.length;
61266
61279
  while (i > 0) {
61267
61280
  i--;
@@ -61269,7 +61282,9 @@ var ts;
61269
61282
  var remove = t.flags & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61270
61283
  t.flags & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61271
61284
  t.flags & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61272
- t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */;
61285
+ t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61286
+ t.flags & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61287
+ isEmptyAnonymousObjectType(t) && includes & 470302716 /* DefinitelyNonNullable */;
61273
61288
  if (remove) {
61274
61289
  ts.orderedRemoveItemAt(types, i);
61275
61290
  }
@@ -61391,7 +61406,7 @@ var ts;
61391
61406
  // a type alias of the form "type List<T> = T & { next: List<T> }" cannot be reduced during its declaration.
61392
61407
  // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
61393
61408
  // for intersections of types with signatures can be deterministic.
61394
- function getIntersectionType(types, aliasSymbol, aliasTypeArguments) {
61409
+ function getIntersectionType(types, aliasSymbol, aliasTypeArguments, noSupertypeReduction) {
61395
61410
  var typeMembershipMap = new ts.Map();
61396
61411
  var includes = addTypesToIntersection(typeMembershipMap, 0, types);
61397
61412
  var typeSet = ts.arrayFrom(typeMembershipMap.values());
@@ -61428,11 +61443,11 @@ var ts;
61428
61443
  if (includes & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61429
61444
  includes & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61430
61445
  includes & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61431
- includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */) {
61432
- removeRedundantPrimitiveTypes(typeSet, includes);
61433
- }
61434
- if (includes & 16777216 /* IncludesEmptyObject */ && includes & 524288 /* Object */) {
61435
- ts.orderedRemoveItemAt(typeSet, ts.findIndex(typeSet, isEmptyAnonymousObjectType));
61446
+ includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */ ||
61447
+ includes & 16384 /* Void */ && includes & 32768 /* Undefined */ ||
61448
+ includes & 16777216 /* IncludesEmptyObject */ && includes & 470302716 /* DefinitelyNonNullable */) {
61449
+ if (!noSupertypeReduction)
61450
+ removeRedundantSupertypes(typeSet, includes);
61436
61451
  }
61437
61452
  if (includes & 262144 /* IncludesMissingType */) {
61438
61453
  typeSet[typeSet.indexOf(undefinedType)] = missingType;
@@ -61471,8 +61486,9 @@ var ts;
61471
61486
  }
61472
61487
  var constituents = getCrossProductIntersections(typeSet);
61473
61488
  // We attach a denormalized origin type when at least one constituent of the cross-product union is an
61474
- // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions).
61475
- var origin = ts.some(constituents, function (t) { return !!(t.flags & 2097152 /* Intersection */); }) ? createOriginUnionOrIntersectionType(2097152 /* Intersection */, typeSet) : undefined;
61489
+ // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions) and
61490
+ // the denormalized origin has fewer constituents than the union itself.
61491
+ var origin = ts.some(constituents, function (t) { return !!(t.flags & 2097152 /* Intersection */); }) && getConstituentCountOfTypes(constituents) > getConstituentCountOfTypes(typeSet) ? createOriginUnionOrIntersectionType(2097152 /* Intersection */, typeSet) : undefined;
61476
61492
  result = getUnionType(constituents, 1 /* Literal */, aliasSymbol, aliasTypeArguments, origin);
61477
61493
  }
61478
61494
  }
@@ -61515,11 +61531,21 @@ var ts;
61515
61531
  }
61516
61532
  return intersections;
61517
61533
  }
61534
+ function getConstituentCount(type) {
61535
+ return !(type.flags & 3145728 /* UnionOrIntersection */) || type.aliasSymbol ? 1 :
61536
+ type.flags & 1048576 /* Union */ && type.origin ? getConstituentCount(type.origin) :
61537
+ getConstituentCountOfTypes(type.types);
61538
+ }
61539
+ function getConstituentCountOfTypes(types) {
61540
+ return ts.reduceLeft(types, function (n, t) { return n + getConstituentCount(t); }, 0);
61541
+ }
61518
61542
  function getTypeFromIntersectionTypeNode(node) {
61519
61543
  var links = getNodeLinks(node);
61520
61544
  if (!links.resolvedType) {
61521
61545
  var aliasSymbol = getAliasSymbolForTypeNode(node);
61522
- links.resolvedType = getIntersectionType(ts.map(node.types, getTypeFromTypeNode), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
61546
+ var types = ts.map(node.types, getTypeFromTypeNode);
61547
+ var noSupertypeReduction = types.length === 2 && !!(types[0].flags & (4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) && types[1] === emptyTypeLiteralType;
61548
+ links.resolvedType = getIntersectionType(types, aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol), noSupertypeReduction);
61523
61549
  }
61524
61550
  return links.resolvedType;
61525
61551
  }
@@ -64305,6 +64331,17 @@ var ts;
64305
64331
  return !!(ts.getObjectFlags(type) & 16 /* Anonymous */ && (type.members && isEmptyResolvedType(type) ||
64306
64332
  type.symbol && type.symbol.flags & 2048 /* TypeLiteral */ && getMembersOfSymbol(type.symbol).size === 0));
64307
64333
  }
64334
+ function isUnknownLikeUnionType(type) {
64335
+ if (strictNullChecks && type.flags & 1048576 /* Union */) {
64336
+ if (!(type.objectFlags & 33554432 /* IsUnknownLikeUnionComputed */)) {
64337
+ var types = type.types;
64338
+ type.objectFlags |= 33554432 /* IsUnknownLikeUnionComputed */ | (types.length >= 3 && types[0].flags & 32768 /* Undefined */ &&
64339
+ types[1].flags & 65536 /* Null */ && ts.some(types, isEmptyAnonymousObjectType) ? 67108864 /* IsUnknownLikeUnion */ : 0);
64340
+ }
64341
+ return !!(type.objectFlags & 67108864 /* IsUnknownLikeUnion */);
64342
+ }
64343
+ return false;
64344
+ }
64308
64345
  function isStringIndexSignatureOnlyType(type) {
64309
64346
  return type.flags & 524288 /* Object */ && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfosOfType(type).length === 1 && !!getIndexInfoOfType(type, stringType) ||
64310
64347
  type.flags & 3145728 /* UnionOrIntersection */ && ts.every(type.types, isStringIndexSignatureOnlyType) ||
@@ -64384,7 +64421,7 @@ var ts;
64384
64421
  return true;
64385
64422
  if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
64386
64423
  return true;
64387
- if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
64424
+ if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */ && !(relation === strictSubtypeRelation && isEmptyAnonymousObjectType(source)))
64388
64425
  return true;
64389
64426
  if (relation === assignableRelation || relation === comparableRelation) {
64390
64427
  if (s & 1 /* Any */)
@@ -64394,6 +64431,9 @@ var ts;
64394
64431
  // bit-flag enum types sometimes look like literal enum types with numeric literal values.
64395
64432
  if (s & (8 /* Number */ | 256 /* NumberLiteral */) && !(s & 1024 /* EnumLiteral */) && (t & 32 /* Enum */ || relation === assignableRelation && t & 256 /* NumberLiteral */ && t & 1024 /* EnumLiteral */))
64396
64433
  return true;
64434
+ // Anything is assignable to a union containing undefined, null, and {}
64435
+ if (isUnknownLikeUnionType(target))
64436
+ return true;
64397
64437
  }
64398
64438
  return false;
64399
64439
  }
@@ -64436,16 +64476,27 @@ var ts;
64436
64476
  function getNormalizedType(type, writing) {
64437
64477
  while (true) {
64438
64478
  var t = isFreshLiteralType(type) ? type.regularType :
64439
- ts.getObjectFlags(type) & 4 /* Reference */ && type.node ? createTypeReference(type.target, getTypeArguments(type)) :
64440
- type.flags & 3145728 /* UnionOrIntersection */ ? getReducedType(type) :
64479
+ ts.getObjectFlags(type) & 4 /* Reference */ ? type.node ? createTypeReference(type.target, getTypeArguments(type)) : getSingleBaseForNonAugmentingSubtype(type) || type :
64480
+ type.flags & 3145728 /* UnionOrIntersection */ ? getNormalizedUnionOrIntersectionType(type, writing) :
64441
64481
  type.flags & 33554432 /* Substitution */ ? writing ? type.baseType : type.substitute :
64442
64482
  type.flags & 25165824 /* Simplifiable */ ? getSimplifiedType(type, writing) :
64443
64483
  type;
64444
- t = getSingleBaseForNonAugmentingSubtype(t) || t;
64445
64484
  if (t === type)
64446
- break;
64485
+ return t;
64447
64486
  type = t;
64448
64487
  }
64488
+ }
64489
+ function getNormalizedUnionOrIntersectionType(type, writing) {
64490
+ var reduced = getReducedType(type);
64491
+ if (reduced !== type) {
64492
+ return reduced;
64493
+ }
64494
+ if (type.flags & 2097152 /* Intersection */) {
64495
+ var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); });
64496
+ if (normalizedTypes !== type.types) {
64497
+ return getIntersectionType(normalizedTypes);
64498
+ }
64499
+ }
64449
64500
  return type;
64450
64501
  }
64451
64502
  /**
@@ -64892,6 +64943,7 @@ var ts;
64892
64943
  return 0 /* False */;
64893
64944
  }
64894
64945
  function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
64946
+ var _a, _b;
64895
64947
  var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
64896
64948
  var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
64897
64949
  source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
@@ -64932,6 +64984,9 @@ var ts;
64932
64984
  return;
64933
64985
  }
64934
64986
  reportRelationError(headMessage, source, target);
64987
+ 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 */))) {
64988
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
64989
+ }
64935
64990
  }
64936
64991
  function traceUnionsOrIntersectionsTooLarge(source, target) {
64937
64992
  if (!ts.tracing) {
@@ -65718,13 +65773,6 @@ var ts;
65718
65773
  // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
65719
65774
  if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
65720
65775
  var constraint = getConstraintOfType(source) || unknownType;
65721
- if (!getConstraintOfType(source) || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
65722
- // A type variable with no constraint is not related to the non-primitive object type.
65723
- if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
65724
- resetErrorInfo(saveErrorInfo);
65725
- return result;
65726
- }
65727
- }
65728
65776
  // 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
65729
65777
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
65730
65778
  resetErrorInfo(saveErrorInfo);
@@ -67198,9 +67246,11 @@ var ts;
67198
67246
  return getSupertypeOrUnion(types);
67199
67247
  }
67200
67248
  var primaryTypes = ts.filter(types, function (t) { return !(t.flags & 98304 /* Nullable */); });
67201
- return primaryTypes.length ?
67202
- getNullableType(getSupertypeOrUnion(primaryTypes), getFalsyFlagsOfTypes(types) & 98304 /* Nullable */) :
67203
- getUnionType(types, 2 /* Subtype */);
67249
+ if (primaryTypes.length) {
67250
+ var supertypeOrUnion = getSupertypeOrUnion(primaryTypes);
67251
+ return primaryTypes === types ? supertypeOrUnion : getUnionType(__spreadArray([supertypeOrUnion], ts.filter(types, function (t) { return !!(t.flags & 98304 /* Nullable */); }), true));
67252
+ }
67253
+ return getUnionType(types, 2 /* Subtype */);
67204
67254
  }
67205
67255
  // Return the leftmost type for which no type to the right is a subtype.
67206
67256
  function getCommonSubtype(types) {
@@ -67399,12 +67449,13 @@ var ts;
67399
67449
  // flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
67400
67450
  // no flags for all other types (including non-falsy literal types).
67401
67451
  function getFalsyFlags(type) {
67402
- return type.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(type.types) :
67403
- type.flags & 128 /* StringLiteral */ ? type.value === "" ? 128 /* StringLiteral */ : 0 :
67404
- type.flags & 256 /* NumberLiteral */ ? type.value === 0 ? 256 /* NumberLiteral */ : 0 :
67405
- type.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(type) ? 2048 /* BigIntLiteral */ : 0 :
67406
- type.flags & 512 /* BooleanLiteral */ ? (type === falseType || type === regularFalseType) ? 512 /* BooleanLiteral */ : 0 :
67407
- type.flags & 117724 /* PossiblyFalsy */;
67452
+ var t = type.flags & 2097152 /* Intersection */ ? getBaseConstraintOrType(type) : type;
67453
+ return t.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(t.types) :
67454
+ t.flags & 128 /* StringLiteral */ ? t.value === "" ? 128 /* StringLiteral */ : 0 :
67455
+ t.flags & 256 /* NumberLiteral */ ? t.value === 0 ? 256 /* NumberLiteral */ : 0 :
67456
+ t.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(t) ? 2048 /* BigIntLiteral */ : 0 :
67457
+ t.flags & 512 /* BooleanLiteral */ ? (t === falseType || t === regularFalseType) ? 512 /* BooleanLiteral */ : 0 :
67458
+ t.flags & 117724 /* PossiblyFalsy */;
67408
67459
  }
67409
67460
  function removeDefinitelyFalsyTypes(type) {
67410
67461
  return getFalsyFlags(type) & 117632 /* DefinitelyFalsy */ ?
@@ -67444,20 +67495,22 @@ var ts;
67444
67495
  return type.flags & 32768 /* Undefined */ ? type : getUnionType([type, isProperty ? missingType : undefinedType]);
67445
67496
  }
67446
67497
  function getGlobalNonNullableTypeInstantiation(type) {
67447
- // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67448
- // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67449
- // that isn't eliminated by a NonNullable<T> instantiation.
67450
- var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67451
67498
  if (!deferredGlobalNonNullableTypeAlias) {
67452
67499
  deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable", 524288 /* TypeAlias */, /*diagnostic*/ undefined) || unknownSymbol;
67453
67500
  }
67454
- // If the NonNullable<T> type is available, return an instantiation. Otherwise just return the reduced type.
67455
67501
  return deferredGlobalNonNullableTypeAlias !== unknownSymbol ?
67456
- getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [reducedType]) :
67457
- reducedType;
67502
+ getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]) :
67503
+ getIntersectionType([type, emptyObjectType]);
67458
67504
  }
67459
67505
  function getNonNullableType(type) {
67460
- return strictNullChecks ? getGlobalNonNullableTypeInstantiation(type) : type;
67506
+ if (strictNullChecks) {
67507
+ // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67508
+ // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67509
+ // that isn't eliminated by a NonNullable<T> instantiation.
67510
+ var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67511
+ return maybeTypeOfKind(reducedType, 465829888 /* Instantiable */) ? getGlobalNonNullableTypeInstantiation(reducedType) : reducedType;
67512
+ }
67513
+ return type;
67461
67514
  }
67462
67515
  function addOptionalTypeMarker(type) {
67463
67516
  return strictNullChecks ? getUnionType([type, optionalType]) : type;
@@ -68138,13 +68191,40 @@ var ts;
68138
68191
  return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
68139
68192
  sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
68140
68193
  }
68141
- function isValidBigIntString(s) {
68194
+ /**
68195
+ * Tests whether the provided string can be parsed as a number.
68196
+ * @param s The string to test.
68197
+ * @param roundTripOnly Indicates the resulting number matches the input when converted back to a string.
68198
+ */
68199
+ function isValidNumberString(s, roundTripOnly) {
68200
+ if (s === "")
68201
+ return false;
68202
+ var n = +s;
68203
+ return isFinite(n) && (!roundTripOnly || "" + n === s);
68204
+ }
68205
+ /**
68206
+ * @param text a valid bigint string excluding a trailing `n`, but including a possible prefix `-`. Use `isValidBigIntString(text, roundTripOnly)` before calling this function.
68207
+ */
68208
+ function parseBigIntLiteralType(text) {
68209
+ var negative = text.startsWith("-");
68210
+ var base10Value = ts.parsePseudoBigInt((negative ? text.slice(1) : text) + "n");
68211
+ return getBigIntLiteralType({ negative: negative, base10Value: base10Value });
68212
+ }
68213
+ /**
68214
+ * Tests whether the provided string can be parsed as a bigint.
68215
+ * @param s The string to test.
68216
+ * @param roundTripOnly Indicates the resulting bigint matches the input when converted back to a string.
68217
+ */
68218
+ function isValidBigIntString(s, roundTripOnly) {
68219
+ if (s === "")
68220
+ return false;
68142
68221
  var scanner = ts.createScanner(99 /* ESNext */, /*skipTrivia*/ false);
68143
68222
  var success = true;
68144
68223
  scanner.setOnError(function () { return success = false; });
68145
68224
  scanner.setText(s + "n");
68146
68225
  var result = scanner.scan();
68147
- if (result === 40 /* MinusToken */) {
68226
+ var negative = result === 40 /* MinusToken */;
68227
+ if (negative) {
68148
68228
  result = scanner.scan();
68149
68229
  }
68150
68230
  var flags = scanner.getTokenFlags();
@@ -68153,7 +68233,8 @@ var ts;
68153
68233
  // * a bigint can be scanned, and that when it is scanned, it is
68154
68234
  // * the full length of the input string (so the scanner is one character beyond the augmented input length)
68155
68235
  // * it does not contain a numeric seperator (the `BigInt` constructor does not accept a numeric seperator in its input)
68156
- return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */);
68236
+ return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */)
68237
+ && (!roundTripOnly || s === ts.pseudoBigIntToString({ negative: negative, base10Value: ts.parsePseudoBigInt(scanner.getTokenValue()) }));
68157
68238
  }
68158
68239
  function isValidTypeForTemplateLiteralPlaceholder(source, target) {
68159
68240
  if (source === target || target.flags & (1 /* Any */ | 4 /* String */)) {
@@ -68161,8 +68242,8 @@ var ts;
68161
68242
  }
68162
68243
  if (source.flags & 128 /* StringLiteral */) {
68163
68244
  var value = source.value;
68164
- return !!(target.flags & 8 /* Number */ && value !== "" && isFinite(+value) ||
68165
- target.flags & 64 /* BigInt */ && value !== "" && isValidBigIntString(value) ||
68245
+ return !!(target.flags & 8 /* Number */ && isValidNumberString(value, /*roundTripOnly*/ false) ||
68246
+ target.flags & 64 /* BigInt */ && isValidBigIntString(value, /*roundTripOnly*/ false) ||
68166
68247
  target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName);
68167
68248
  }
68168
68249
  if (source.flags & 134217728 /* TemplateLiteral */) {
@@ -68735,8 +68816,57 @@ var ts;
68735
68816
  // upon instantiation, would collapse all the placeholders to just 'string', and an assignment check might
68736
68817
  // succeed. That would be a pointless and confusing outcome.
68737
68818
  if (matches || ts.every(target.texts, function (s) { return s.length === 0; })) {
68819
+ var _loop_23 = function (i) {
68820
+ var source_1 = matches ? matches[i] : neverType;
68821
+ var target_3 = types[i];
68822
+ // If we are inferring from a string literal type to a type variable whose constraint includes one of the
68823
+ // allowed template literal placeholder types, infer from a literal type corresponding to the constraint.
68824
+ if (source_1.flags & 128 /* StringLiteral */ && target_3.flags & 8650752 /* TypeVariable */) {
68825
+ var inferenceContext = getInferenceInfoForType(target_3);
68826
+ var constraint = inferenceContext ? getBaseConstraintOfType(inferenceContext.typeParameter) : undefined;
68827
+ if (constraint && !isTypeAny(constraint)) {
68828
+ var constraintTypes = constraint.flags & 1048576 /* Union */ ? constraint.types : [constraint];
68829
+ var allTypeFlags_1 = ts.reduceLeft(constraintTypes, function (flags, t) { return flags | t.flags; }, 0);
68830
+ // If the constraint contains `string`, we don't need to look for a more preferred type
68831
+ if (!(allTypeFlags_1 & 4 /* String */)) {
68832
+ var str_1 = source_1.value;
68833
+ // If the type contains `number` or a number literal and the string isn't a valid number, exclude numbers
68834
+ if (allTypeFlags_1 & 296 /* NumberLike */ && !isValidNumberString(str_1, /*roundTripOnly*/ true)) {
68835
+ allTypeFlags_1 &= ~296 /* NumberLike */;
68836
+ }
68837
+ // If the type contains `bigint` or a bigint literal and the string isn't a valid bigint, exclude bigints
68838
+ if (allTypeFlags_1 & 2112 /* BigIntLike */ && !isValidBigIntString(str_1, /*roundTripOnly*/ true)) {
68839
+ allTypeFlags_1 &= ~2112 /* BigIntLike */;
68840
+ }
68841
+ // for each type in the constraint, find the highest priority matching type
68842
+ var matchingType = ts.reduceLeft(constraintTypes, function (left, right) {
68843
+ return !(right.flags & allTypeFlags_1) ? left :
68844
+ left.flags & 4 /* String */ ? left : right.flags & 4 /* String */ ? source_1 :
68845
+ left.flags & 134217728 /* TemplateLiteral */ ? left : right.flags & 134217728 /* TemplateLiteral */ && isTypeMatchedByTemplateLiteralType(source_1, right) ? source_1 :
68846
+ left.flags & 268435456 /* StringMapping */ ? left : right.flags & 268435456 /* StringMapping */ && str_1 === applyStringMapping(right.symbol, str_1) ? source_1 :
68847
+ left.flags & 128 /* StringLiteral */ ? left : right.flags & 128 /* StringLiteral */ && right.value === str_1 ? right :
68848
+ left.flags & 8 /* Number */ ? left : right.flags & 8 /* Number */ ? getNumberLiteralType(+str_1) :
68849
+ left.flags & 32 /* Enum */ ? left : right.flags & 32 /* Enum */ ? getNumberLiteralType(+str_1) :
68850
+ left.flags & 256 /* NumberLiteral */ ? left : right.flags & 256 /* NumberLiteral */ && right.value === +str_1 ? right :
68851
+ left.flags & 64 /* BigInt */ ? left : right.flags & 64 /* BigInt */ ? parseBigIntLiteralType(str_1) :
68852
+ left.flags & 2048 /* BigIntLiteral */ ? left : right.flags & 2048 /* BigIntLiteral */ && ts.pseudoBigIntToString(right.value) === str_1 ? right :
68853
+ left.flags & 16 /* Boolean */ ? left : right.flags & 16 /* Boolean */ ? str_1 === "true" ? trueType : str_1 === "false" ? falseType : booleanType :
68854
+ left.flags & 512 /* BooleanLiteral */ ? left : right.flags & 512 /* BooleanLiteral */ && right.intrinsicName === str_1 ? right :
68855
+ left.flags & 32768 /* Undefined */ ? left : right.flags & 32768 /* Undefined */ && right.intrinsicName === str_1 ? right :
68856
+ left.flags & 65536 /* Null */ ? left : right.flags & 65536 /* Null */ && right.intrinsicName === str_1 ? right :
68857
+ left;
68858
+ }, neverType);
68859
+ if (!(matchingType.flags & 131072 /* Never */)) {
68860
+ inferFromTypes(matchingType, target_3);
68861
+ return "continue";
68862
+ }
68863
+ }
68864
+ }
68865
+ }
68866
+ inferFromTypes(source_1, target_3);
68867
+ };
68738
68868
  for (var i = 0; i < types.length; i++) {
68739
- inferFromTypes(matches ? matches[i] : neverType, types[i]);
68869
+ _loop_23(i);
68740
68870
  }
68741
68871
  }
68742
68872
  }
@@ -69254,7 +69384,7 @@ var ts;
69254
69384
  function mapTypesByKeyProperty(types, name) {
69255
69385
  var map = new ts.Map();
69256
69386
  var count = 0;
69257
- var _loop_23 = function (type) {
69387
+ var _loop_24 = function (type) {
69258
69388
  if (type.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 58982400 /* InstantiableNonPrimitive */)) {
69259
69389
  var discriminant = getTypeOfPropertyOfType(type, name);
69260
69390
  if (discriminant) {
@@ -69280,7 +69410,7 @@ var ts;
69280
69410
  };
69281
69411
  for (var _i = 0, types_16 = types; _i < types_16.length; _i++) {
69282
69412
  var type = types_16[_i];
69283
- var state_9 = _loop_23(type);
69413
+ var state_9 = _loop_24(type);
69284
69414
  if (typeof state_9 === "object")
69285
69415
  return state_9.value;
69286
69416
  }
@@ -69488,6 +69618,24 @@ var ts;
69488
69618
  function getTypeWithFacts(type, include) {
69489
69619
  return filterType(type, function (t) { return (getTypeFacts(t) & include) !== 0; });
69490
69620
  }
69621
+ function getIntersectionWithFacts(type, facts) {
69622
+ var reduced = recombineUnknownType(getTypeWithFacts(strictNullChecks && type.flags & 2 /* Unknown */ ? unknownUnionType : type, facts));
69623
+ if (strictNullChecks) {
69624
+ switch (facts) {
69625
+ case 524288 /* NEUndefined */:
69626
+ 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; });
69627
+ case 1048576 /* NENull */:
69628
+ 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; });
69629
+ case 2097152 /* NEUndefinedOrNull */:
69630
+ case 4194304 /* Truthy */:
69631
+ return mapType(reduced, function (t) { return getTypeFacts(t) & 262144 /* EQUndefinedOrNull */ ? getGlobalNonNullableTypeInstantiation(t) : t; });
69632
+ }
69633
+ }
69634
+ return reduced;
69635
+ }
69636
+ function recombineUnknownType(type) {
69637
+ return type === unknownUnionType ? unknownType : type;
69638
+ }
69491
69639
  function getTypeWithDefault(type, defaultExpression) {
69492
69640
  return defaultExpression ?
69493
69641
  getUnionType([getNonUndefinedType(type), getTypeOfExpression(defaultExpression)]) :
@@ -70545,7 +70693,7 @@ var ts;
70545
70693
  if (isEvolvingArrayTypeList(types)) {
70546
70694
  return getEvolvingArrayType(getUnionType(ts.map(types, getElementTypeOfEvolvingArrayType)));
70547
70695
  }
70548
- var result = getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction);
70696
+ var result = recombineUnknownType(getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction));
70549
70697
  if (result !== declaredType && result.flags & declaredType.flags & 1048576 /* Union */ && ts.arraysEqual(result.types, declaredType.types)) {
70550
70698
  return declaredType;
70551
70699
  }
@@ -70647,8 +70795,7 @@ var ts;
70647
70795
  }
70648
70796
  function narrowTypeByTruthiness(type, expr, assumeTrue) {
70649
70797
  if (isMatchingReference(reference, expr)) {
70650
- return type.flags & 2 /* Unknown */ && assumeTrue ? nonNullUnknownType :
70651
- getTypeWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70798
+ return getIntersectionWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70652
70799
  }
70653
70800
  if (strictNullChecks && assumeTrue && optionalChainContainsReference(expr, reference)) {
70654
70801
  type = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
@@ -70801,9 +70948,6 @@ var ts;
70801
70948
  assumeTrue = !assumeTrue;
70802
70949
  }
70803
70950
  var valueType = getTypeOfExpression(value);
70804
- if (assumeTrue && (type.flags & 2 /* Unknown */) && (operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */) && (valueType.flags & 65536 /* Null */)) {
70805
- return getUnionType([nullType, undefinedType]);
70806
- }
70807
70951
  if ((type.flags & 2 /* Unknown */) && assumeTrue && (operator === 36 /* EqualsEqualsEqualsToken */ || operator === 37 /* ExclamationEqualsEqualsToken */)) {
70808
70952
  if (valueType.flags & (131068 /* Primitive */ | 67108864 /* NonPrimitive */)) {
70809
70953
  return valueType;
@@ -70823,7 +70967,7 @@ var ts;
70823
70967
  valueType.flags & 65536 /* Null */ ?
70824
70968
  assumeTrue ? 131072 /* EQNull */ : 1048576 /* NENull */ :
70825
70969
  assumeTrue ? 65536 /* EQUndefined */ : 524288 /* NEUndefined */;
70826
- return type.flags & 2 /* Unknown */ && facts & (1048576 /* NENull */ | 2097152 /* NEUndefinedOrNull */) ? nonNullUnknownType : getTypeWithFacts(type, facts);
70970
+ return getIntersectionWithFacts(type, facts);
70827
70971
  }
70828
70972
  if (assumeTrue) {
70829
70973
  var filterFn = operator === 34 /* EqualsEqualsToken */ ?
@@ -70851,17 +70995,11 @@ var ts;
70851
70995
  if (type.flags & 1 /* Any */ && literal.text === "function") {
70852
70996
  return type;
70853
70997
  }
70854
- if (assumeTrue && type.flags & 2 /* Unknown */ && literal.text === "object") {
70855
- // The non-null unknown type is used to track whether a previous narrowing operation has removed the null type
70856
- // from the unknown type. For example, the expression `x && typeof x === 'object'` first narrows x to the non-null
70857
- // unknown type, and then narrows that to the non-primitive type.
70858
- return type === nonNullUnknownType ? nonPrimitiveType : getUnionType([nonPrimitiveType, nullType]);
70859
- }
70860
70998
  var facts = assumeTrue ?
70861
70999
  typeofEQFacts.get(literal.text) || 128 /* TypeofEQHostObject */ :
70862
71000
  typeofNEFacts.get(literal.text) || 32768 /* TypeofNEHostObject */;
70863
71001
  var impliedType = getImpliedTypeFromTypeofGuard(type, literal.text);
70864
- return getTypeWithFacts(assumeTrue && impliedType ? mapType(type, narrowUnionMemberByTypeof(impliedType)) : type, facts);
71002
+ return getTypeWithFacts(assumeTrue && impliedType ? narrowTypeByImpliedType(type, impliedType) : type, facts);
70865
71003
  }
70866
71004
  function narrowTypeBySwitchOptionalChainContainment(type, switchStatement, clauseStart, clauseEnd, clauseCheck) {
70867
71005
  var everyClauseChecks = clauseStart !== clauseEnd && ts.every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), clauseCheck);
@@ -70910,10 +71048,10 @@ var ts;
70910
71048
  }
70911
71049
  function getImpliedTypeFromTypeofGuard(type, text) {
70912
71050
  switch (text) {
71051
+ case "object":
71052
+ return type.flags & 1 /* Any */ ? type : getUnionType([nullType, nonPrimitiveType]);
70913
71053
  case "function":
70914
71054
  return type.flags & 1 /* Any */ ? type : globalFunctionType;
70915
- case "object":
70916
- return type.flags & 2 /* Unknown */ ? getUnionType([nonPrimitiveType, nullType]) : type;
70917
71055
  default:
70918
71056
  return typeofTypesByName.get(text);
70919
71057
  }
@@ -70924,22 +71062,27 @@ var ts;
70924
71062
  // the guard. For example: narrowing `{} | undefined` by `"boolean"` should produce the type `boolean`, not
70925
71063
  // the filtered type `{}`. For this reason we narrow constituents of the union individually, in addition to
70926
71064
  // filtering by type-facts.
70927
- function narrowUnionMemberByTypeof(candidate) {
70928
- return function (type) {
70929
- if (isTypeSubtypeOf(type, candidate)) {
70930
- return type;
70931
- }
70932
- if (isTypeSubtypeOf(candidate, type)) {
70933
- return candidate;
71065
+ function narrowTypeByImpliedType(type, candidate) {
71066
+ if (type.flags & 3 /* AnyOrUnknown */) {
71067
+ return candidate;
71068
+ }
71069
+ return mapType(type, function (t) {
71070
+ if (isTypeRelatedTo(t, candidate, strictSubtypeRelation)) {
71071
+ return t;
70934
71072
  }
70935
- if (type.flags & 465829888 /* Instantiable */) {
70936
- var constraint = getBaseConstraintOfType(type) || anyType;
70937
- if (isTypeSubtypeOf(candidate, constraint)) {
70938
- return getIntersectionType([type, candidate]);
71073
+ return mapType(candidate, function (c) {
71074
+ if (!areTypesComparable(t, c)) {
71075
+ return neverType;
70939
71076
  }
70940
- }
70941
- return type;
70942
- };
71077
+ if (c.flags & 131068 /* Primitive */ && t.flags & 524288 /* Object */ && !isEmptyAnonymousObjectType(t)) {
71078
+ return isTypeSubtypeOf(c, t) ? c : neverType;
71079
+ }
71080
+ if (c === globalFunctionType && isTypeSubtypeOf(c, t)) {
71081
+ return c;
71082
+ }
71083
+ return getIntersectionType([t, c]);
71084
+ });
71085
+ });
70943
71086
  }
70944
71087
  function narrowBySwitchOnTypeOf(type, switchStatement, clauseStart, clauseEnd) {
70945
71088
  var switchWitnesses = getSwitchClauseTypeOfWitnesses(switchStatement, /*retainDefault*/ true);
@@ -70998,7 +71141,7 @@ var ts;
70998
71141
  because it is caught in the first clause.
70999
71142
  */
71000
71143
  var impliedType = getTypeWithFacts(getUnionType(clauseWitnesses.map(function (text) { return getImpliedTypeFromTypeofGuard(type, text) || type; })), switchFacts);
71001
- return getTypeWithFacts(mapType(type, narrowUnionMemberByTypeof(impliedType)), switchFacts);
71144
+ return getTypeWithFacts(narrowTypeByImpliedType(type, impliedType), switchFacts);
71002
71145
  }
71003
71146
  function isMatchingConstructorReference(expr) {
71004
71147
  return (ts.isPropertyAccessExpression(expr) && ts.idText(expr.name) === "constructor" ||
@@ -71302,7 +71445,9 @@ var ts;
71302
71445
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
71303
71446
  }
71304
71447
  function isGenericTypeWithUnionConstraint(type) {
71305
- return !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71448
+ return type.flags & 2097152 /* Intersection */ ?
71449
+ ts.some(type.types, isGenericTypeWithUnionConstraint) :
71450
+ !!(type.flags & 465829888 /* Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* Nullable */ | 1048576 /* Union */));
71306
71451
  }
71307
71452
  function isGenericTypeWithoutNullableConstraint(type) {
71308
71453
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
@@ -71330,7 +71475,7 @@ var ts;
71330
71475
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
71331
71476
  someType(type, isGenericTypeWithUnionConstraint) &&
71332
71477
  (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
71333
- return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ ? getBaseConstraintOrType(t) : t; }) : type;
71478
+ return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
71334
71479
  }
71335
71480
  function isExportOrExportExpression(location) {
71336
71481
  return !!ts.findAncestor(location, function (n) {
@@ -75668,7 +75813,7 @@ var ts;
75668
75813
  if (spreadIndex >= 0) {
75669
75814
  // Create synthetic arguments from spreads of tuple types.
75670
75815
  var effectiveArgs_1 = args.slice(0, spreadIndex);
75671
- var _loop_24 = function (i) {
75816
+ var _loop_25 = function (i) {
75672
75817
  var arg = args[i];
75673
75818
  // We can call checkExpressionCached because spread expressions never have a contextual type.
75674
75819
  var spreadType = arg.kind === 225 /* SpreadElement */ && (flowLoopCount ? checkExpression(arg.expression) : checkExpressionCached(arg.expression));
@@ -75685,7 +75830,7 @@ var ts;
75685
75830
  }
75686
75831
  };
75687
75832
  for (var i = spreadIndex; i < args.length; i++) {
75688
- _loop_24(i);
75833
+ _loop_25(i);
75689
75834
  }
75690
75835
  return effectiveArgs_1;
75691
75836
  }
@@ -76005,7 +76150,7 @@ var ts;
76005
76150
  var min_3 = Number.MAX_VALUE;
76006
76151
  var minIndex = 0;
76007
76152
  var i_1 = 0;
76008
- var _loop_25 = function (c) {
76153
+ var _loop_26 = function (c) {
76009
76154
  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)); };
76010
76155
  var diags_2 = getSignatureApplicabilityError(node, args, c, assignableRelation, 0 /* Normal */, /*reportErrors*/ true, chain_2);
76011
76156
  if (diags_2) {
@@ -76023,7 +76168,7 @@ var ts;
76023
76168
  };
76024
76169
  for (var _a = 0, candidatesForArgumentError_1 = candidatesForArgumentError; _a < candidatesForArgumentError_1.length; _a++) {
76025
76170
  var c = candidatesForArgumentError_1[_a];
76026
- _loop_25(c);
76171
+ _loop_26(c);
76027
76172
  }
76028
76173
  var diags_3 = max > 1 ? allDiagnostics[minIndex] : ts.flatten(allDiagnostics);
76029
76174
  ts.Debug.assert(diags_3.length > 0, "No errors reported for 3 or fewer overload signatures");
@@ -76181,7 +76326,7 @@ var ts;
76181
76326
  }
76182
76327
  var _a = ts.minAndMax(candidates, getNumNonRestParameters), minArgumentCount = _a.min, maxNonRestParam = _a.max;
76183
76328
  var parameters = [];
76184
- var _loop_26 = function (i) {
76329
+ var _loop_27 = function (i) {
76185
76330
  var symbols = ts.mapDefined(candidates, function (s) { return signatureHasRestParameter(s) ?
76186
76331
  i < s.parameters.length - 1 ? s.parameters[i] : ts.last(s.parameters) :
76187
76332
  i < s.parameters.length ? s.parameters[i] : undefined; });
@@ -76189,7 +76334,7 @@ var ts;
76189
76334
  parameters.push(createCombinedSymbolFromTypes(symbols, ts.mapDefined(candidates, function (candidate) { return tryGetTypeAtPosition(candidate, i); })));
76190
76335
  };
76191
76336
  for (var i = 0; i < maxNonRestParam; i++) {
76192
- _loop_26(i);
76337
+ _loop_27(i);
76193
76338
  }
76194
76339
  var restParameterSymbols = ts.mapDefined(candidates, function (c) { return signatureHasRestParameter(c) ? ts.last(c.parameters) : undefined; });
76195
76340
  var flags = 0 /* None */;
@@ -80246,7 +80391,7 @@ var ts;
80246
80391
  var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
80247
80392
  if (indexSymbol === null || indexSymbol === void 0 ? void 0 : indexSymbol.declarations) {
80248
80393
  var indexSignatureMap_1 = new ts.Map();
80249
- var _loop_27 = function (declaration) {
80394
+ var _loop_28 = function (declaration) {
80250
80395
  if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
80251
80396
  forEachType(getTypeFromTypeNode(declaration.parameters[0].type), function (type) {
80252
80397
  var entry = indexSignatureMap_1.get(getTypeId(type));
@@ -80261,7 +80406,7 @@ var ts;
80261
80406
  };
80262
80407
  for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
80263
80408
  var declaration = _a[_i];
80264
- _loop_27(declaration);
80409
+ _loop_28(declaration);
80265
80410
  }
80266
80411
  indexSignatureMap_1.forEach(function (entry) {
80267
80412
  if (entry.declarations.length > 1) {
@@ -82457,7 +82602,7 @@ var ts;
82457
82602
  }
82458
82603
  // For a commonjs `const x = require`, validate the alias and exit
82459
82604
  var symbol = getSymbolOfNode(node);
82460
- if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
82605
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* BindingElement */ ? node.parent.parent : node)) {
82461
82606
  checkAliasSymbol(node);
82462
82607
  return;
82463
82608
  }
@@ -83722,7 +83867,7 @@ var ts;
83722
83867
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83723
83868
  var localPropDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
83724
83869
  name && name.kind === 162 /* ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
83725
- var _loop_28 = function (info) {
83870
+ var _loop_29 = function (info) {
83726
83871
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
83727
83872
  // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
83728
83873
  // in the containing type, or (c) the containing type is an interface and no base interface contains both the property and
@@ -83735,7 +83880,7 @@ var ts;
83735
83880
  };
83736
83881
  for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
83737
83882
  var info = indexInfos_9[_i];
83738
- _loop_28(info);
83883
+ _loop_29(info);
83739
83884
  }
83740
83885
  }
83741
83886
  function checkIndexConstraintForIndexSignature(type, checkInfo) {
@@ -83743,7 +83888,7 @@ var ts;
83743
83888
  var indexInfos = getApplicableIndexInfos(type, checkInfo.keyType);
83744
83889
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83745
83890
  var localCheckDeclaration = declaration && getParentOfSymbol(getSymbolOfNode(declaration)) === type.symbol ? declaration : undefined;
83746
- var _loop_29 = function (info) {
83891
+ var _loop_30 = function (info) {
83747
83892
  if (info === checkInfo)
83748
83893
  return "continue";
83749
83894
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
@@ -83758,7 +83903,7 @@ var ts;
83758
83903
  };
83759
83904
  for (var _i = 0, indexInfos_10 = indexInfos; _i < indexInfos_10.length; _i++) {
83760
83905
  var info = indexInfos_10[_i];
83761
- _loop_29(info);
83906
+ _loop_30(info);
83762
83907
  }
83763
83908
  }
83764
83909
  function checkTypeNameIsReserved(name, message) {
@@ -84077,7 +84222,7 @@ var ts;
84077
84222
  var baseTypes = baseTypeNode && getBaseTypes(type);
84078
84223
  var baseWithThis = (baseTypes === null || baseTypes === void 0 ? void 0 : baseTypes.length) ? getTypeWithThisArgument(ts.first(baseTypes), type.thisType) : undefined;
84079
84224
  var baseStaticType = getBaseConstructorTypeOfClass(type);
84080
- var _loop_30 = function (member) {
84225
+ var _loop_31 = function (member) {
84081
84226
  if (ts.hasAmbientModifier(member)) {
84082
84227
  return "continue";
84083
84228
  }
@@ -84094,7 +84239,7 @@ var ts;
84094
84239
  };
84095
84240
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84096
84241
  var member = _a[_i];
84097
- _loop_30(member);
84242
+ _loop_31(member);
84098
84243
  }
84099
84244
  }
84100
84245
  /**
@@ -84182,7 +84327,7 @@ var ts;
84182
84327
  function issueMemberSpecificError(node, typeWithThis, baseWithThis, broadDiag) {
84183
84328
  // iterate over all implemented properties and issue errors on each one which isn't compatible, rather than the class as a whole, if possible
84184
84329
  var issuedMemberError = false;
84185
- var _loop_31 = function (member) {
84330
+ var _loop_32 = function (member) {
84186
84331
  if (ts.isStatic(member)) {
84187
84332
  return "continue";
84188
84333
  }
@@ -84201,7 +84346,7 @@ var ts;
84201
84346
  };
84202
84347
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84203
84348
  var member = _a[_i];
84204
- _loop_31(member);
84349
+ _loop_32(member);
84205
84350
  }
84206
84351
  if (!issuedMemberError) {
84207
84352
  // check again with diagnostics to generate a less-specific error
@@ -122169,7 +122314,7 @@ var ts;
122169
122314
  });
122170
122315
  // Sort by paths closest to importing file Name directory
122171
122316
  var sortedPaths = [];
122172
- var _loop_32 = function (directory) {
122317
+ var _loop_33 = function (directory) {
122173
122318
  var directoryStart = ts.ensureTrailingDirectorySeparator(directory);
122174
122319
  var pathsInDirectory;
122175
122320
  allFileNames.forEach(function (_a, fileName) {
@@ -122193,7 +122338,7 @@ var ts;
122193
122338
  };
122194
122339
  var out_directory_1;
122195
122340
  for (var directory = ts.getDirectoryPath(importingFileName); allFileNames.size !== 0;) {
122196
- var state_10 = _loop_32(directory);
122341
+ var state_10 = _loop_33(directory);
122197
122342
  directory = out_directory_1;
122198
122343
  if (state_10 === "break")
122199
122344
  break;