typescript 4.8.0-dev.20220525 → 4.8.0-dev.20220528

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.20220525";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220528";
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) {
@@ -42032,7 +42037,7 @@ var ts;
42032
42037
  }
42033
42038
  if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) {
42034
42039
  return {
42035
- key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec),
42040
+ key: ts.removeTrailingDirectorySeparator(useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec)),
42036
42041
  flags: 1 /* Recursive */
42037
42042
  };
42038
42043
  }
@@ -43137,16 +43142,20 @@ var ts;
43137
43142
  function nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) {
43138
43143
  return nodeNextModuleNameResolverWorker(NodeResolutionFeatures.NodeNextDefault, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode);
43139
43144
  }
43145
+ var jsOnlyExtensions = [Extensions.JavaScript];
43146
+ var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript];
43147
+ var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false);
43148
+ var tsconfigExtensions = [Extensions.TSConfig];
43140
43149
  function nodeNextModuleNameResolverWorker(features, moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode) {
43141
43150
  var containingDirectory = ts.getDirectoryPath(containingFile);
43142
43151
  // es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features
43143
43152
  var esmMode = resolutionMode === ts.ModuleKind.ESNext ? NodeResolutionFeatures.EsmMode : 0;
43144
- return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions, redirectedReference);
43153
+ var extensions = compilerOptions.noDtsResolution ? [Extensions.TsOnly, Extensions.JavaScript] : tsExtensions;
43154
+ if (compilerOptions.resolveJsonModule) {
43155
+ extensions = __spreadArray(__spreadArray([], extensions, true), [Extensions.Json], false);
43156
+ }
43157
+ return nodeModuleNameResolverWorker(features | esmMode, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference);
43145
43158
  }
43146
- var jsOnlyExtensions = [Extensions.JavaScript];
43147
- var tsExtensions = [Extensions.TypeScript, Extensions.JavaScript];
43148
- var tsPlusJsonExtensions = __spreadArray(__spreadArray([], tsExtensions, true), [Extensions.Json], false);
43149
- var tsconfigExtensions = [Extensions.TSConfig];
43150
43159
  function tryResolveJSModuleWorker(moduleName, initialDir, host) {
43151
43160
  return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined);
43152
43161
  }
@@ -46931,12 +46940,14 @@ var ts;
46931
46940
  }
46932
46941
  }
46933
46942
  function setCommonJsModuleIndicator(node) {
46934
- if (file.externalModuleIndicator) {
46943
+ if (file.externalModuleIndicator && file.externalModuleIndicator !== true) {
46935
46944
  return false;
46936
46945
  }
46937
46946
  if (!file.commonJsModuleIndicator) {
46938
46947
  file.commonJsModuleIndicator = node;
46939
- bindSourceFileAsExternalModule();
46948
+ if (!file.externalModuleIndicator) {
46949
+ bindSourceFileAsExternalModule();
46950
+ }
46940
46951
  }
46941
46952
  return true;
46942
46953
  }
@@ -47350,7 +47361,11 @@ var ts;
47350
47361
  checkStrictModeEvalOrArguments(node, node.name);
47351
47362
  }
47352
47363
  if (!ts.isBindingPattern(node.name)) {
47353
- 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 */)) {
47354
47369
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
47355
47370
  }
47356
47371
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -48527,6 +48542,7 @@ var ts;
48527
48542
  var emptyTypeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type" /* Type */);
48528
48543
  emptyTypeLiteralSymbol.members = ts.createSymbolTable();
48529
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;
48530
48546
  var emptyGenericType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
48531
48547
  emptyGenericType.instantiations = new ts.Map();
48532
48548
  var anyFunctionType = createAnonymousType(undefined, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
@@ -50177,7 +50193,8 @@ var ts;
50177
50193
  && isAliasableOrJsExpression(node.parent.right)
50178
50194
  || node.kind === 297 /* ShorthandPropertyAssignment */
50179
50195
  || node.kind === 296 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
50180
- || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
50196
+ || node.kind === 254 /* VariableDeclaration */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)
50197
+ || node.kind === 203 /* BindingElement */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent);
50181
50198
  }
50182
50199
  function isAliasableOrJsExpression(e) {
50183
50200
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50270,7 +50287,7 @@ var ts;
50270
50287
  return hasExportAssignmentSymbol(moduleSymbol);
50271
50288
  }
50272
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
50273
- 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);
50274
50291
  }
50275
50292
  function getTargetOfImportClause(node, dontResolveAlias) {
50276
50293
  var _a;
@@ -58696,7 +58713,7 @@ var ts;
58696
58713
  }
58697
58714
  }
58698
58715
  }
58699
- else if (t.flags & 469892092 /* DisjointDomains */) {
58716
+ else if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58700
58717
  hasDisjointDomainType = true;
58701
58718
  }
58702
58719
  }
@@ -58708,7 +58725,7 @@ var ts;
58708
58725
  // intersection operation to reduce the union constraints.
58709
58726
  for (var _a = 0, types_6 = types; _a < types_6.length; _a++) {
58710
58727
  var t = types_6[_a];
58711
- if (t.flags & 469892092 /* DisjointDomains */) {
58728
+ if (t.flags & 469892092 /* DisjointDomains */ || isEmptyAnonymousObjectType(t)) {
58712
58729
  constraints = ts.append(constraints, t);
58713
58730
  }
58714
58731
  }
@@ -61257,7 +61274,7 @@ var ts;
61257
61274
  }
61258
61275
  return includes;
61259
61276
  }
61260
- function removeRedundantPrimitiveTypes(types, includes) {
61277
+ function removeRedundantSupertypes(types, includes) {
61261
61278
  var i = types.length;
61262
61279
  while (i > 0) {
61263
61280
  i--;
@@ -61265,7 +61282,9 @@ var ts;
61265
61282
  var remove = t.flags & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61266
61283
  t.flags & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61267
61284
  t.flags & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61268
- 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 */;
61269
61288
  if (remove) {
61270
61289
  ts.orderedRemoveItemAt(types, i);
61271
61290
  }
@@ -61387,7 +61406,7 @@ var ts;
61387
61406
  // a type alias of the form "type List<T> = T & { next: List<T> }" cannot be reduced during its declaration.
61388
61407
  // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
61389
61408
  // for intersections of types with signatures can be deterministic.
61390
- function getIntersectionType(types, aliasSymbol, aliasTypeArguments) {
61409
+ function getIntersectionType(types, aliasSymbol, aliasTypeArguments, noSupertypeReduction) {
61391
61410
  var typeMembershipMap = new ts.Map();
61392
61411
  var includes = addTypesToIntersection(typeMembershipMap, 0, types);
61393
61412
  var typeSet = ts.arrayFrom(typeMembershipMap.values());
@@ -61424,11 +61443,11 @@ var ts;
61424
61443
  if (includes & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61425
61444
  includes & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61426
61445
  includes & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61427
- includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */) {
61428
- removeRedundantPrimitiveTypes(typeSet, includes);
61429
- }
61430
- if (includes & 16777216 /* IncludesEmptyObject */ && includes & 524288 /* Object */) {
61431
- 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);
61432
61451
  }
61433
61452
  if (includes & 262144 /* IncludesMissingType */) {
61434
61453
  typeSet[typeSet.indexOf(undefinedType)] = missingType;
@@ -61467,8 +61486,9 @@ var ts;
61467
61486
  }
61468
61487
  var constituents = getCrossProductIntersections(typeSet);
61469
61488
  // We attach a denormalized origin type when at least one constituent of the cross-product union is an
61470
- // intersection (i.e. when the intersection didn't just reduce one or more unions to smaller unions).
61471
- 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;
61472
61492
  result = getUnionType(constituents, 1 /* Literal */, aliasSymbol, aliasTypeArguments, origin);
61473
61493
  }
61474
61494
  }
@@ -61511,11 +61531,21 @@ var ts;
61511
61531
  }
61512
61532
  return intersections;
61513
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
+ }
61514
61542
  function getTypeFromIntersectionTypeNode(node) {
61515
61543
  var links = getNodeLinks(node);
61516
61544
  if (!links.resolvedType) {
61517
61545
  var aliasSymbol = getAliasSymbolForTypeNode(node);
61518
- 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);
61519
61549
  }
61520
61550
  return links.resolvedType;
61521
61551
  }
@@ -64301,6 +64331,17 @@ var ts;
64301
64331
  return !!(ts.getObjectFlags(type) & 16 /* Anonymous */ && (type.members && isEmptyResolvedType(type) ||
64302
64332
  type.symbol && type.symbol.flags & 2048 /* TypeLiteral */ && getMembersOfSymbol(type.symbol).size === 0));
64303
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
+ }
64304
64345
  function isStringIndexSignatureOnlyType(type) {
64305
64346
  return type.flags & 524288 /* Object */ && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfosOfType(type).length === 1 && !!getIndexInfoOfType(type, stringType) ||
64306
64347
  type.flags & 3145728 /* UnionOrIntersection */ && ts.every(type.types, isStringIndexSignatureOnlyType) ||
@@ -64380,7 +64421,7 @@ var ts;
64380
64421
  return true;
64381
64422
  if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
64382
64423
  return true;
64383
- if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
64424
+ if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */ && !(relation === strictSubtypeRelation && isEmptyAnonymousObjectType(source)))
64384
64425
  return true;
64385
64426
  if (relation === assignableRelation || relation === comparableRelation) {
64386
64427
  if (s & 1 /* Any */)
@@ -64390,6 +64431,9 @@ var ts;
64390
64431
  // bit-flag enum types sometimes look like literal enum types with numeric literal values.
64391
64432
  if (s & (8 /* Number */ | 256 /* NumberLiteral */) && !(s & 1024 /* EnumLiteral */) && (t & 32 /* Enum */ || relation === assignableRelation && t & 256 /* NumberLiteral */ && t & 1024 /* EnumLiteral */))
64392
64433
  return true;
64434
+ // Anything is assignable to a union containing undefined, null, and {}
64435
+ if (isUnknownLikeUnionType(target))
64436
+ return true;
64393
64437
  }
64394
64438
  return false;
64395
64439
  }
@@ -64432,16 +64476,27 @@ var ts;
64432
64476
  function getNormalizedType(type, writing) {
64433
64477
  while (true) {
64434
64478
  var t = isFreshLiteralType(type) ? type.regularType :
64435
- ts.getObjectFlags(type) & 4 /* Reference */ && type.node ? createTypeReference(type.target, getTypeArguments(type)) :
64436
- 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) :
64437
64481
  type.flags & 33554432 /* Substitution */ ? writing ? type.baseType : type.substitute :
64438
64482
  type.flags & 25165824 /* Simplifiable */ ? getSimplifiedType(type, writing) :
64439
64483
  type;
64440
- t = getSingleBaseForNonAugmentingSubtype(t) || t;
64441
64484
  if (t === type)
64442
- break;
64485
+ return t;
64443
64486
  type = t;
64444
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
+ }
64445
64500
  return type;
64446
64501
  }
64447
64502
  /**
@@ -64888,6 +64943,7 @@ var ts;
64888
64943
  return 0 /* False */;
64889
64944
  }
64890
64945
  function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
64946
+ var _a, _b;
64891
64947
  var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
64892
64948
  var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
64893
64949
  source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
@@ -64928,6 +64984,9 @@ var ts;
64928
64984
  return;
64929
64985
  }
64930
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
+ }
64931
64990
  }
64932
64991
  function traceUnionsOrIntersectionsTooLarge(source, target) {
64933
64992
  if (!ts.tracing) {
@@ -65714,13 +65773,6 @@ var ts;
65714
65773
  // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
65715
65774
  if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
65716
65775
  var constraint = getConstraintOfType(source) || unknownType;
65717
- if (!getConstraintOfType(source) || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
65718
- // A type variable with no constraint is not related to the non-primitive object type.
65719
- if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
65720
- resetErrorInfo(saveErrorInfo);
65721
- return result;
65722
- }
65723
- }
65724
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
65725
65777
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
65726
65778
  resetErrorInfo(saveErrorInfo);
@@ -67194,9 +67246,11 @@ var ts;
67194
67246
  return getSupertypeOrUnion(types);
67195
67247
  }
67196
67248
  var primaryTypes = ts.filter(types, function (t) { return !(t.flags & 98304 /* Nullable */); });
67197
- return primaryTypes.length ?
67198
- getNullableType(getSupertypeOrUnion(primaryTypes), getFalsyFlagsOfTypes(types) & 98304 /* Nullable */) :
67199
- 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 */);
67200
67254
  }
67201
67255
  // Return the leftmost type for which no type to the right is a subtype.
67202
67256
  function getCommonSubtype(types) {
@@ -67395,12 +67449,13 @@ var ts;
67395
67449
  // flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
67396
67450
  // no flags for all other types (including non-falsy literal types).
67397
67451
  function getFalsyFlags(type) {
67398
- return type.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(type.types) :
67399
- type.flags & 128 /* StringLiteral */ ? type.value === "" ? 128 /* StringLiteral */ : 0 :
67400
- type.flags & 256 /* NumberLiteral */ ? type.value === 0 ? 256 /* NumberLiteral */ : 0 :
67401
- type.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(type) ? 2048 /* BigIntLiteral */ : 0 :
67402
- type.flags & 512 /* BooleanLiteral */ ? (type === falseType || type === regularFalseType) ? 512 /* BooleanLiteral */ : 0 :
67403
- 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 */;
67404
67459
  }
67405
67460
  function removeDefinitelyFalsyTypes(type) {
67406
67461
  return getFalsyFlags(type) & 117632 /* DefinitelyFalsy */ ?
@@ -67440,20 +67495,22 @@ var ts;
67440
67495
  return type.flags & 32768 /* Undefined */ ? type : getUnionType([type, isProperty ? missingType : undefinedType]);
67441
67496
  }
67442
67497
  function getGlobalNonNullableTypeInstantiation(type) {
67443
- // First reduce away any constituents that are assignable to 'undefined' or 'null'. This not only eliminates
67444
- // 'undefined' and 'null', but also higher-order types such as a type parameter 'U extends undefined | null'
67445
- // that isn't eliminated by a NonNullable<T> instantiation.
67446
- var reducedType = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
67447
67498
  if (!deferredGlobalNonNullableTypeAlias) {
67448
67499
  deferredGlobalNonNullableTypeAlias = getGlobalSymbol("NonNullable", 524288 /* TypeAlias */, /*diagnostic*/ undefined) || unknownSymbol;
67449
67500
  }
67450
- // If the NonNullable<T> type is available, return an instantiation. Otherwise just return the reduced type.
67451
67501
  return deferredGlobalNonNullableTypeAlias !== unknownSymbol ?
67452
- getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [reducedType]) :
67453
- reducedType;
67502
+ getTypeAliasInstantiation(deferredGlobalNonNullableTypeAlias, [type]) :
67503
+ getIntersectionType([type, emptyObjectType]);
67454
67504
  }
67455
67505
  function getNonNullableType(type) {
67456
- 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;
67457
67514
  }
67458
67515
  function addOptionalTypeMarker(type) {
67459
67516
  return strictNullChecks ? getUnionType([type, optionalType]) : type;
@@ -68134,13 +68191,40 @@ var ts;
68134
68191
  return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
68135
68192
  sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
68136
68193
  }
68137
- 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;
68138
68221
  var scanner = ts.createScanner(99 /* ESNext */, /*skipTrivia*/ false);
68139
68222
  var success = true;
68140
68223
  scanner.setOnError(function () { return success = false; });
68141
68224
  scanner.setText(s + "n");
68142
68225
  var result = scanner.scan();
68143
- if (result === 40 /* MinusToken */) {
68226
+ var negative = result === 40 /* MinusToken */;
68227
+ if (negative) {
68144
68228
  result = scanner.scan();
68145
68229
  }
68146
68230
  var flags = scanner.getTokenFlags();
@@ -68149,7 +68233,8 @@ var ts;
68149
68233
  // * a bigint can be scanned, and that when it is scanned, it is
68150
68234
  // * the full length of the input string (so the scanner is one character beyond the augmented input length)
68151
68235
  // * it does not contain a numeric seperator (the `BigInt` constructor does not accept a numeric seperator in its input)
68152
- 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()) }));
68153
68238
  }
68154
68239
  function isValidTypeForTemplateLiteralPlaceholder(source, target) {
68155
68240
  if (source === target || target.flags & (1 /* Any */ | 4 /* String */)) {
@@ -68157,8 +68242,8 @@ var ts;
68157
68242
  }
68158
68243
  if (source.flags & 128 /* StringLiteral */) {
68159
68244
  var value = source.value;
68160
- return !!(target.flags & 8 /* Number */ && value !== "" && isFinite(+value) ||
68161
- 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) ||
68162
68247
  target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName);
68163
68248
  }
68164
68249
  if (source.flags & 134217728 /* TemplateLiteral */) {
@@ -68731,8 +68816,57 @@ var ts;
68731
68816
  // upon instantiation, would collapse all the placeholders to just 'string', and an assignment check might
68732
68817
  // succeed. That would be a pointless and confusing outcome.
68733
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
+ };
68734
68868
  for (var i = 0; i < types.length; i++) {
68735
- inferFromTypes(matches ? matches[i] : neverType, types[i]);
68869
+ _loop_23(i);
68736
68870
  }
68737
68871
  }
68738
68872
  }
@@ -69250,7 +69384,7 @@ var ts;
69250
69384
  function mapTypesByKeyProperty(types, name) {
69251
69385
  var map = new ts.Map();
69252
69386
  var count = 0;
69253
- var _loop_23 = function (type) {
69387
+ var _loop_24 = function (type) {
69254
69388
  if (type.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 58982400 /* InstantiableNonPrimitive */)) {
69255
69389
  var discriminant = getTypeOfPropertyOfType(type, name);
69256
69390
  if (discriminant) {
@@ -69276,7 +69410,7 @@ var ts;
69276
69410
  };
69277
69411
  for (var _i = 0, types_16 = types; _i < types_16.length; _i++) {
69278
69412
  var type = types_16[_i];
69279
- var state_9 = _loop_23(type);
69413
+ var state_9 = _loop_24(type);
69280
69414
  if (typeof state_9 === "object")
69281
69415
  return state_9.value;
69282
69416
  }
@@ -69484,6 +69618,24 @@ var ts;
69484
69618
  function getTypeWithFacts(type, include) {
69485
69619
  return filterType(type, function (t) { return (getTypeFacts(t) & include) !== 0; });
69486
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
+ }
69487
69639
  function getTypeWithDefault(type, defaultExpression) {
69488
69640
  return defaultExpression ?
69489
69641
  getUnionType([getNonUndefinedType(type), getTypeOfExpression(defaultExpression)]) :
@@ -70541,7 +70693,7 @@ var ts;
70541
70693
  if (isEvolvingArrayTypeList(types)) {
70542
70694
  return getEvolvingArrayType(getUnionType(ts.map(types, getElementTypeOfEvolvingArrayType)));
70543
70695
  }
70544
- var result = getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction);
70696
+ var result = recombineUnknownType(getUnionType(ts.sameMap(types, finalizeEvolvingArrayType), subtypeReduction));
70545
70697
  if (result !== declaredType && result.flags & declaredType.flags & 1048576 /* Union */ && ts.arraysEqual(result.types, declaredType.types)) {
70546
70698
  return declaredType;
70547
70699
  }
@@ -70643,8 +70795,7 @@ var ts;
70643
70795
  }
70644
70796
  function narrowTypeByTruthiness(type, expr, assumeTrue) {
70645
70797
  if (isMatchingReference(reference, expr)) {
70646
- return type.flags & 2 /* Unknown */ && assumeTrue ? nonNullUnknownType :
70647
- getTypeWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70798
+ return getIntersectionWithFacts(type, assumeTrue ? 4194304 /* Truthy */ : 8388608 /* Falsy */);
70648
70799
  }
70649
70800
  if (strictNullChecks && assumeTrue && optionalChainContainsReference(expr, reference)) {
70650
70801
  type = getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */);
@@ -70797,9 +70948,6 @@ var ts;
70797
70948
  assumeTrue = !assumeTrue;
70798
70949
  }
70799
70950
  var valueType = getTypeOfExpression(value);
70800
- if (assumeTrue && (type.flags & 2 /* Unknown */) && (operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */) && (valueType.flags & 65536 /* Null */)) {
70801
- return getUnionType([nullType, undefinedType]);
70802
- }
70803
70951
  if ((type.flags & 2 /* Unknown */) && assumeTrue && (operator === 36 /* EqualsEqualsEqualsToken */ || operator === 37 /* ExclamationEqualsEqualsToken */)) {
70804
70952
  if (valueType.flags & (131068 /* Primitive */ | 67108864 /* NonPrimitive */)) {
70805
70953
  return valueType;
@@ -70819,7 +70967,7 @@ var ts;
70819
70967
  valueType.flags & 65536 /* Null */ ?
70820
70968
  assumeTrue ? 131072 /* EQNull */ : 1048576 /* NENull */ :
70821
70969
  assumeTrue ? 65536 /* EQUndefined */ : 524288 /* NEUndefined */;
70822
- return type.flags & 2 /* Unknown */ && facts & (1048576 /* NENull */ | 2097152 /* NEUndefinedOrNull */) ? nonNullUnknownType : getTypeWithFacts(type, facts);
70970
+ return getIntersectionWithFacts(type, facts);
70823
70971
  }
70824
70972
  if (assumeTrue) {
70825
70973
  var filterFn = operator === 34 /* EqualsEqualsToken */ ?
@@ -70847,17 +70995,11 @@ var ts;
70847
70995
  if (type.flags & 1 /* Any */ && literal.text === "function") {
70848
70996
  return type;
70849
70997
  }
70850
- if (assumeTrue && type.flags & 2 /* Unknown */ && literal.text === "object") {
70851
- // The non-null unknown type is used to track whether a previous narrowing operation has removed the null type
70852
- // from the unknown type. For example, the expression `x && typeof x === 'object'` first narrows x to the non-null
70853
- // unknown type, and then narrows that to the non-primitive type.
70854
- return type === nonNullUnknownType ? nonPrimitiveType : getUnionType([nonPrimitiveType, nullType]);
70855
- }
70856
70998
  var facts = assumeTrue ?
70857
70999
  typeofEQFacts.get(literal.text) || 128 /* TypeofEQHostObject */ :
70858
71000
  typeofNEFacts.get(literal.text) || 32768 /* TypeofNEHostObject */;
70859
71001
  var impliedType = getImpliedTypeFromTypeofGuard(type, literal.text);
70860
- return getTypeWithFacts(assumeTrue && impliedType ? mapType(type, narrowUnionMemberByTypeof(impliedType)) : type, facts);
71002
+ return getTypeWithFacts(assumeTrue && impliedType ? narrowTypeByImpliedType(type, impliedType) : type, facts);
70861
71003
  }
70862
71004
  function narrowTypeBySwitchOptionalChainContainment(type, switchStatement, clauseStart, clauseEnd, clauseCheck) {
70863
71005
  var everyClauseChecks = clauseStart !== clauseEnd && ts.every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), clauseCheck);
@@ -70906,10 +71048,10 @@ var ts;
70906
71048
  }
70907
71049
  function getImpliedTypeFromTypeofGuard(type, text) {
70908
71050
  switch (text) {
71051
+ case "object":
71052
+ return type.flags & 1 /* Any */ ? type : getUnionType([nullType, nonPrimitiveType]);
70909
71053
  case "function":
70910
71054
  return type.flags & 1 /* Any */ ? type : globalFunctionType;
70911
- case "object":
70912
- return type.flags & 2 /* Unknown */ ? getUnionType([nonPrimitiveType, nullType]) : type;
70913
71055
  default:
70914
71056
  return typeofTypesByName.get(text);
70915
71057
  }
@@ -70920,22 +71062,27 @@ var ts;
70920
71062
  // the guard. For example: narrowing `{} | undefined` by `"boolean"` should produce the type `boolean`, not
70921
71063
  // the filtered type `{}`. For this reason we narrow constituents of the union individually, in addition to
70922
71064
  // filtering by type-facts.
70923
- function narrowUnionMemberByTypeof(candidate) {
70924
- return function (type) {
70925
- if (isTypeSubtypeOf(type, candidate)) {
70926
- return type;
70927
- }
70928
- if (isTypeSubtypeOf(candidate, type)) {
70929
- 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;
70930
71072
  }
70931
- if (type.flags & 465829888 /* Instantiable */) {
70932
- var constraint = getBaseConstraintOfType(type) || anyType;
70933
- if (isTypeSubtypeOf(candidate, constraint)) {
70934
- return getIntersectionType([type, candidate]);
71073
+ return mapType(candidate, function (c) {
71074
+ if (!areTypesComparable(t, c)) {
71075
+ return neverType;
70935
71076
  }
70936
- }
70937
- return type;
70938
- };
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
+ });
70939
71086
  }
70940
71087
  function narrowBySwitchOnTypeOf(type, switchStatement, clauseStart, clauseEnd) {
70941
71088
  var switchWitnesses = getSwitchClauseTypeOfWitnesses(switchStatement, /*retainDefault*/ true);
@@ -70994,7 +71141,7 @@ var ts;
70994
71141
  because it is caught in the first clause.
70995
71142
  */
70996
71143
  var impliedType = getTypeWithFacts(getUnionType(clauseWitnesses.map(function (text) { return getImpliedTypeFromTypeofGuard(type, text) || type; })), switchFacts);
70997
- return getTypeWithFacts(mapType(type, narrowUnionMemberByTypeof(impliedType)), switchFacts);
71144
+ return getTypeWithFacts(narrowTypeByImpliedType(type, impliedType), switchFacts);
70998
71145
  }
70999
71146
  function isMatchingConstructorReference(expr) {
71000
71147
  return (ts.isPropertyAccessExpression(expr) && ts.idText(expr.name) === "constructor" ||
@@ -71298,7 +71445,9 @@ var ts;
71298
71445
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
71299
71446
  }
71300
71447
  function isGenericTypeWithUnionConstraint(type) {
71301
- 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 */));
71302
71451
  }
71303
71452
  function isGenericTypeWithoutNullableConstraint(type) {
71304
71453
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
@@ -71326,7 +71475,7 @@ var ts;
71326
71475
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
71327
71476
  someType(type, isGenericTypeWithUnionConstraint) &&
71328
71477
  (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
71329
- return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ ? getBaseConstraintOrType(t) : t; }) : type;
71478
+ return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
71330
71479
  }
71331
71480
  function isExportOrExportExpression(location) {
71332
71481
  return !!ts.findAncestor(location, function (n) {
@@ -75664,7 +75813,7 @@ var ts;
75664
75813
  if (spreadIndex >= 0) {
75665
75814
  // Create synthetic arguments from spreads of tuple types.
75666
75815
  var effectiveArgs_1 = args.slice(0, spreadIndex);
75667
- var _loop_24 = function (i) {
75816
+ var _loop_25 = function (i) {
75668
75817
  var arg = args[i];
75669
75818
  // We can call checkExpressionCached because spread expressions never have a contextual type.
75670
75819
  var spreadType = arg.kind === 225 /* SpreadElement */ && (flowLoopCount ? checkExpression(arg.expression) : checkExpressionCached(arg.expression));
@@ -75681,7 +75830,7 @@ var ts;
75681
75830
  }
75682
75831
  };
75683
75832
  for (var i = spreadIndex; i < args.length; i++) {
75684
- _loop_24(i);
75833
+ _loop_25(i);
75685
75834
  }
75686
75835
  return effectiveArgs_1;
75687
75836
  }
@@ -76001,7 +76150,7 @@ var ts;
76001
76150
  var min_3 = Number.MAX_VALUE;
76002
76151
  var minIndex = 0;
76003
76152
  var i_1 = 0;
76004
- var _loop_25 = function (c) {
76153
+ var _loop_26 = function (c) {
76005
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)); };
76006
76155
  var diags_2 = getSignatureApplicabilityError(node, args, c, assignableRelation, 0 /* Normal */, /*reportErrors*/ true, chain_2);
76007
76156
  if (diags_2) {
@@ -76019,7 +76168,7 @@ var ts;
76019
76168
  };
76020
76169
  for (var _a = 0, candidatesForArgumentError_1 = candidatesForArgumentError; _a < candidatesForArgumentError_1.length; _a++) {
76021
76170
  var c = candidatesForArgumentError_1[_a];
76022
- _loop_25(c);
76171
+ _loop_26(c);
76023
76172
  }
76024
76173
  var diags_3 = max > 1 ? allDiagnostics[minIndex] : ts.flatten(allDiagnostics);
76025
76174
  ts.Debug.assert(diags_3.length > 0, "No errors reported for 3 or fewer overload signatures");
@@ -76177,7 +76326,7 @@ var ts;
76177
76326
  }
76178
76327
  var _a = ts.minAndMax(candidates, getNumNonRestParameters), minArgumentCount = _a.min, maxNonRestParam = _a.max;
76179
76328
  var parameters = [];
76180
- var _loop_26 = function (i) {
76329
+ var _loop_27 = function (i) {
76181
76330
  var symbols = ts.mapDefined(candidates, function (s) { return signatureHasRestParameter(s) ?
76182
76331
  i < s.parameters.length - 1 ? s.parameters[i] : ts.last(s.parameters) :
76183
76332
  i < s.parameters.length ? s.parameters[i] : undefined; });
@@ -76185,7 +76334,7 @@ var ts;
76185
76334
  parameters.push(createCombinedSymbolFromTypes(symbols, ts.mapDefined(candidates, function (candidate) { return tryGetTypeAtPosition(candidate, i); })));
76186
76335
  };
76187
76336
  for (var i = 0; i < maxNonRestParam; i++) {
76188
- _loop_26(i);
76337
+ _loop_27(i);
76189
76338
  }
76190
76339
  var restParameterSymbols = ts.mapDefined(candidates, function (c) { return signatureHasRestParameter(c) ? ts.last(c.parameters) : undefined; });
76191
76340
  var flags = 0 /* None */;
@@ -80242,7 +80391,7 @@ var ts;
80242
80391
  var indexSymbol = getIndexSymbol(getSymbolOfNode(node));
80243
80392
  if (indexSymbol === null || indexSymbol === void 0 ? void 0 : indexSymbol.declarations) {
80244
80393
  var indexSignatureMap_1 = new ts.Map();
80245
- var _loop_27 = function (declaration) {
80394
+ var _loop_28 = function (declaration) {
80246
80395
  if (declaration.parameters.length === 1 && declaration.parameters[0].type) {
80247
80396
  forEachType(getTypeFromTypeNode(declaration.parameters[0].type), function (type) {
80248
80397
  var entry = indexSignatureMap_1.get(getTypeId(type));
@@ -80257,7 +80406,7 @@ var ts;
80257
80406
  };
80258
80407
  for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) {
80259
80408
  var declaration = _a[_i];
80260
- _loop_27(declaration);
80409
+ _loop_28(declaration);
80261
80410
  }
80262
80411
  indexSignatureMap_1.forEach(function (entry) {
80263
80412
  if (entry.declarations.length > 1) {
@@ -82453,7 +82602,7 @@ var ts;
82453
82602
  }
82454
82603
  // For a commonjs `const x = require`, validate the alias and exit
82455
82604
  var symbol = getSymbolOfNode(node);
82456
- if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
82605
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node.kind === 203 /* BindingElement */ ? node.parent.parent : node)) {
82457
82606
  checkAliasSymbol(node);
82458
82607
  return;
82459
82608
  }
@@ -83718,7 +83867,7 @@ var ts;
83718
83867
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83719
83868
  var localPropDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
83720
83869
  name && name.kind === 162 /* ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
83721
- var _loop_28 = function (info) {
83870
+ var _loop_29 = function (info) {
83722
83871
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
83723
83872
  // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
83724
83873
  // in the containing type, or (c) the containing type is an interface and no base interface contains both the property and
@@ -83731,7 +83880,7 @@ var ts;
83731
83880
  };
83732
83881
  for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
83733
83882
  var info = indexInfos_9[_i];
83734
- _loop_28(info);
83883
+ _loop_29(info);
83735
83884
  }
83736
83885
  }
83737
83886
  function checkIndexConstraintForIndexSignature(type, checkInfo) {
@@ -83739,7 +83888,7 @@ var ts;
83739
83888
  var indexInfos = getApplicableIndexInfos(type, checkInfo.keyType);
83740
83889
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
83741
83890
  var localCheckDeclaration = declaration && getParentOfSymbol(getSymbolOfNode(declaration)) === type.symbol ? declaration : undefined;
83742
- var _loop_29 = function (info) {
83891
+ var _loop_30 = function (info) {
83743
83892
  if (info === checkInfo)
83744
83893
  return "continue";
83745
83894
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
@@ -83754,7 +83903,7 @@ var ts;
83754
83903
  };
83755
83904
  for (var _i = 0, indexInfos_10 = indexInfos; _i < indexInfos_10.length; _i++) {
83756
83905
  var info = indexInfos_10[_i];
83757
- _loop_29(info);
83906
+ _loop_30(info);
83758
83907
  }
83759
83908
  }
83760
83909
  function checkTypeNameIsReserved(name, message) {
@@ -84073,7 +84222,7 @@ var ts;
84073
84222
  var baseTypes = baseTypeNode && getBaseTypes(type);
84074
84223
  var baseWithThis = (baseTypes === null || baseTypes === void 0 ? void 0 : baseTypes.length) ? getTypeWithThisArgument(ts.first(baseTypes), type.thisType) : undefined;
84075
84224
  var baseStaticType = getBaseConstructorTypeOfClass(type);
84076
- var _loop_30 = function (member) {
84225
+ var _loop_31 = function (member) {
84077
84226
  if (ts.hasAmbientModifier(member)) {
84078
84227
  return "continue";
84079
84228
  }
@@ -84090,7 +84239,7 @@ var ts;
84090
84239
  };
84091
84240
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84092
84241
  var member = _a[_i];
84093
- _loop_30(member);
84242
+ _loop_31(member);
84094
84243
  }
84095
84244
  }
84096
84245
  /**
@@ -84178,7 +84327,7 @@ var ts;
84178
84327
  function issueMemberSpecificError(node, typeWithThis, baseWithThis, broadDiag) {
84179
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
84180
84329
  var issuedMemberError = false;
84181
- var _loop_31 = function (member) {
84330
+ var _loop_32 = function (member) {
84182
84331
  if (ts.isStatic(member)) {
84183
84332
  return "continue";
84184
84333
  }
@@ -84197,7 +84346,7 @@ var ts;
84197
84346
  };
84198
84347
  for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
84199
84348
  var member = _a[_i];
84200
- _loop_31(member);
84349
+ _loop_32(member);
84201
84350
  }
84202
84351
  if (!issuedMemberError) {
84203
84352
  // check again with diagnostics to generate a less-specific error
@@ -122165,7 +122314,7 @@ var ts;
122165
122314
  });
122166
122315
  // Sort by paths closest to importing file Name directory
122167
122316
  var sortedPaths = [];
122168
- var _loop_32 = function (directory) {
122317
+ var _loop_33 = function (directory) {
122169
122318
  var directoryStart = ts.ensureTrailingDirectorySeparator(directory);
122170
122319
  var pathsInDirectory;
122171
122320
  allFileNames.forEach(function (_a, fileName) {
@@ -122189,7 +122338,7 @@ var ts;
122189
122338
  };
122190
122339
  var out_directory_1;
122191
122340
  for (var directory = ts.getDirectoryPath(importingFileName); allFileNames.size !== 0;) {
122192
- var state_10 = _loop_32(directory);
122341
+ var state_10 = _loop_33(directory);
122193
122342
  directory = out_directory_1;
122194
122343
  if (state_10 === "break")
122195
122344
  break;
@@ -123636,6 +123785,7 @@ var ts;
123636
123785
  }
123637
123786
  function reloadFileNamesFromConfigFile() {
123638
123787
  writeLog("Reloading new file names and options");
123788
+ reloadLevel = ts.ConfigFileProgramReloadLevel.None;
123639
123789
  rootFileNames = ts.getFileNamesFromConfigSpecs(compilerOptions.configFile.configFileSpecs, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), currentDirectory), compilerOptions, parseConfigFileHost, extraFileExtensions);
123640
123790
  if (ts.updateErrorForNoInputFiles(rootFileNames, ts.getNormalizedAbsolutePath(configFileName, currentDirectory), compilerOptions.configFile.configFileSpecs, configFileParsingDiagnostics, canConfigFileJsonReportNoInputFiles)) {
123641
123791
  hasChangedConfigFileParsingErrors = true;