typescript 4.8.0-dev.20220705 → 4.8.0-dev.20220706

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220705";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220706";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -4931,6 +4931,7 @@ var ts;
4931
4931
  NodeBuilderFlags[NodeBuilderFlags["UseAliasDefinedOutsideCurrentScope"] = 16384] = "UseAliasDefinedOutsideCurrentScope";
4932
4932
  NodeBuilderFlags[NodeBuilderFlags["UseSingleQuotesForStringLiteralType"] = 268435456] = "UseSingleQuotesForStringLiteralType";
4933
4933
  NodeBuilderFlags[NodeBuilderFlags["NoTypeReduction"] = 536870912] = "NoTypeReduction";
4934
+ NodeBuilderFlags[NodeBuilderFlags["OmitThisParameter"] = 33554432] = "OmitThisParameter";
4934
4935
  // Error handling
4935
4936
  NodeBuilderFlags[NodeBuilderFlags["AllowThisInObjectLiteral"] = 32768] = "AllowThisInObjectLiteral";
4936
4937
  NodeBuilderFlags[NodeBuilderFlags["AllowQualifiedNameInPlaceOfIdentifier"] = 65536] = "AllowQualifiedNameInPlaceOfIdentifier";
@@ -4971,6 +4972,7 @@ var ts;
4971
4972
  TypeFormatFlags[TypeFormatFlags["UseAliasDefinedOutsideCurrentScope"] = 16384] = "UseAliasDefinedOutsideCurrentScope";
4972
4973
  TypeFormatFlags[TypeFormatFlags["UseSingleQuotesForStringLiteralType"] = 268435456] = "UseSingleQuotesForStringLiteralType";
4973
4974
  TypeFormatFlags[TypeFormatFlags["NoTypeReduction"] = 536870912] = "NoTypeReduction";
4975
+ TypeFormatFlags[TypeFormatFlags["OmitThisParameter"] = 33554432] = "OmitThisParameter";
4974
4976
  // Error Handling
4975
4977
  TypeFormatFlags[TypeFormatFlags["AllowUniqueESSymbolType"] = 1048576] = "AllowUniqueESSymbolType";
4976
4978
  // TypeFormatFlags exclusive
@@ -4982,7 +4984,7 @@ var ts;
4982
4984
  TypeFormatFlags[TypeFormatFlags["InFirstTypeArgument"] = 4194304] = "InFirstTypeArgument";
4983
4985
  TypeFormatFlags[TypeFormatFlags["InTypeAlias"] = 8388608] = "InTypeAlias";
4984
4986
  /** @deprecated */ TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 0] = "WriteOwnNameForAnyLike";
4985
- TypeFormatFlags[TypeFormatFlags["NodeBuilderFlagsMask"] = 814775659] = "NodeBuilderFlagsMask";
4987
+ TypeFormatFlags[TypeFormatFlags["NodeBuilderFlagsMask"] = 848330091] = "NodeBuilderFlagsMask";
4986
4988
  })(TypeFormatFlags = ts.TypeFormatFlags || (ts.TypeFormatFlags = {}));
4987
4989
  var SymbolFormatFlags;
4988
4990
  (function (SymbolFormatFlags) {
@@ -49293,6 +49295,7 @@ var ts;
49293
49295
  var stringMappingTypes = new ts.Map();
49294
49296
  var substitutionTypes = new ts.Map();
49295
49297
  var subtypeReductionCache = new ts.Map();
49298
+ var cachedTypes = new ts.Map();
49296
49299
  var evolvingArrayTypes = [];
49297
49300
  var undefinedProperties = new ts.Map();
49298
49301
  var markerTypes = new ts.Set();
@@ -49546,6 +49549,14 @@ var ts;
49546
49549
  ];
49547
49550
  initializeTypeChecker();
49548
49551
  return checker;
49552
+ function getCachedType(key) {
49553
+ return key ? cachedTypes.get(key) : undefined;
49554
+ }
49555
+ function setCachedType(key, type) {
49556
+ if (key)
49557
+ cachedTypes.set(key, type);
49558
+ return type;
49559
+ }
49549
49560
  function getJsxNamespace(location) {
49550
49561
  if (location) {
49551
49562
  var file = ts.getSourceFileOfNode(location);
@@ -52940,7 +52951,7 @@ var ts;
52940
52951
  }
52941
52952
  function toNodeBuilderFlags(flags) {
52942
52953
  if (flags === void 0) { flags = 0 /* None */; }
52943
- return flags & 814775659 /* NodeBuilderFlagsMask */;
52954
+ return flags & 848330091 /* NodeBuilderFlagsMask */;
52944
52955
  }
52945
52956
  function isClassInstanceSide(type) {
52946
52957
  return !!type.symbol && !!(type.symbol.flags & 32 /* Class */) && (type === getDeclaredTypeOfClassOrInterface(type.symbol) || (!!(type.flags & 524288 /* Object */) && !!(ts.getObjectFlags(type) & 16777216 /* IsClassInstanceClone */)));
@@ -53919,7 +53930,7 @@ var ts;
53919
53930
  var expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
53920
53931
  // If the expanded parameter list had a variadic in a non-trailing position, don't expand it
53921
53932
  var parameters = (ts.some(expandedParams, function (p) { return p !== expandedParams[expandedParams.length - 1] && !!(ts.getCheckFlags(p) & 32768 /* RestParameter */); }) ? signature.parameters : expandedParams).map(function (parameter) { return symbolToParameterDeclaration(parameter, context, kind === 171 /* Constructor */, options === null || options === void 0 ? void 0 : options.privateSymbolVisitor, options === null || options === void 0 ? void 0 : options.bundledImports); });
53922
- var thisParameter = tryGetThisParameterDeclaration(signature, context);
53933
+ var thisParameter = context.flags & 33554432 /* OmitThisParameter */ ? undefined : tryGetThisParameterDeclaration(signature, context);
53923
53934
  if (thisParameter) {
53924
53935
  parameters.unshift(thisParameter);
53925
53936
  }
@@ -54978,12 +54989,11 @@ var ts;
54978
54989
  if (skipMembershipCheck || (!!ts.length(symbol.declarations) && ts.some(symbol.declarations, function (d) { return !!ts.findAncestor(d, function (n) { return n === enclosingDeclaration; }); }))) {
54979
54990
  var oldContext = context;
54980
54991
  context = cloneNodeBuilderContext(context);
54981
- var result = serializeSymbolWorker(symbol, isPrivate, propertyAsAlias);
54992
+ serializeSymbolWorker(symbol, isPrivate, propertyAsAlias);
54982
54993
  if (context.reportedDiagnostic) {
54983
54994
  oldcontext.reportedDiagnostic = context.reportedDiagnostic; // hoist diagnostic result into outer context
54984
54995
  }
54985
54996
  context = oldContext;
54986
- return result;
54987
54997
  }
54988
54998
  }
54989
54999
  // Synthesize declarations for a symbol - might be an Interface, a Class, a Namespace, a Type, a Variable (const, let, or var), an Alias
@@ -58040,7 +58050,7 @@ var ts;
58040
58050
  error(declaration.typeExpression.type, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
58041
58051
  }
58042
58052
  else {
58043
- error(ts.isNamedDeclaration(declaration) ? declaration.name : declaration || declaration, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
58053
+ error(ts.isNamedDeclaration(declaration) ? declaration.name || declaration : declaration, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
58044
58054
  }
58045
58055
  }
58046
58056
  links.declaredType = type;
@@ -68223,9 +68233,14 @@ var ts;
68223
68233
  type.flags & 256 /* NumberLiteral */ ? numberType :
68224
68234
  type.flags & 2048 /* BigIntLiteral */ ? bigintType :
68225
68235
  type.flags & 512 /* BooleanLiteral */ ? booleanType :
68226
- type.flags & 1048576 /* Union */ ? mapType(type, getBaseTypeOfLiteralType) :
68236
+ type.flags & 1048576 /* Union */ ? getBaseTypeOfLiteralTypeUnion(type) :
68227
68237
  type;
68228
68238
  }
68239
+ function getBaseTypeOfLiteralTypeUnion(type) {
68240
+ var _a;
68241
+ var key = "B" + getTypeId(type);
68242
+ return (_a = getCachedType(key)) !== null && _a !== void 0 ? _a : setCachedType(key, mapType(type, getBaseTypeOfLiteralType));
68243
+ }
68229
68244
  function getWidenedLiteralType(type) {
68230
68245
  return type.flags & 1024 /* EnumLiteral */ && isFreshLiteralType(type) ? getBaseTypeOfEnumLiteralType(type) :
68231
68246
  type.flags & 128 /* StringLiteral */ && isFreshLiteralType(type) ? stringType :
@@ -70368,23 +70383,25 @@ var ts;
70368
70383
  // For example, when a variable of type number | string | boolean is assigned a value of type number | boolean,
70369
70384
  // we remove type string.
70370
70385
  function getAssignmentReducedType(declaredType, assignedType) {
70371
- if (declaredType !== assignedType) {
70372
- if (assignedType.flags & 131072 /* Never */) {
70373
- return assignedType;
70374
- }
70375
- var reducedType = filterType(declaredType, function (t) { return typeMaybeAssignableTo(assignedType, t); });
70376
- if (assignedType.flags & 512 /* BooleanLiteral */ && isFreshLiteralType(assignedType)) {
70377
- reducedType = mapType(reducedType, getFreshTypeOfLiteralType); // Ensure that if the assignment is a fresh type, that we narrow to fresh types
70378
- }
70379
- // Our crude heuristic produces an invalid result in some cases: see GH#26130.
70380
- // For now, when that happens, we give up and don't narrow at all. (This also
70381
- // means we'll never narrow for erroneous assignments where the assigned type
70382
- // is not assignable to the declared type.)
70383
- if (isTypeAssignableTo(assignedType, reducedType)) {
70384
- return reducedType;
70385
- }
70386
+ var _a;
70387
+ if (declaredType === assignedType) {
70388
+ return declaredType;
70386
70389
  }
70387
- return declaredType;
70390
+ if (assignedType.flags & 131072 /* Never */) {
70391
+ return assignedType;
70392
+ }
70393
+ var key = "A" + getTypeId(declaredType) + "," + getTypeId(assignedType);
70394
+ return (_a = getCachedType(key)) !== null && _a !== void 0 ? _a : setCachedType(key, getAssignmentReducedTypeWorker(declaredType, assignedType));
70395
+ }
70396
+ function getAssignmentReducedTypeWorker(declaredType, assignedType) {
70397
+ var filteredType = filterType(declaredType, function (t) { return typeMaybeAssignableTo(assignedType, t); });
70398
+ // Ensure that we narrow to fresh types if the assignment is a fresh boolean literal type.
70399
+ var reducedType = assignedType.flags & 512 /* BooleanLiteral */ && isFreshLiteralType(assignedType) ? mapType(filteredType, getFreshTypeOfLiteralType) : filteredType;
70400
+ // Our crude heuristic produces an invalid result in some cases: see GH#26130.
70401
+ // For now, when that happens, we give up and don't narrow at all. (This also
70402
+ // means we'll never narrow for erroneous assignments where the assigned type
70403
+ // is not assignable to the declared type.)
70404
+ return isTypeAssignableTo(assignedType, reducedType) ? reducedType : declaredType;
70388
70405
  }
70389
70406
  function isFunctionObjectType(type) {
70390
70407
  // We do a quick check for a "bind" property before performing the more expensive subtype
@@ -71790,7 +71807,7 @@ var ts;
71790
71807
  var targetType = ts.hasStaticModifier(ts.Debug.checkDefined(symbol.valueDeclaration, "should always have a declaration"))
71791
71808
  ? getTypeOfSymbol(classSymbol)
71792
71809
  : getDeclaredTypeOfSymbol(classSymbol);
71793
- return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom);
71810
+ return getNarrowedType(type, targetType, assumeTrue, /*checkDerived*/ true);
71794
71811
  }
71795
71812
  function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) {
71796
71813
  // We are in a branch of obj?.foo === value (or any one of the other equality operators). We narrow obj as follows:
@@ -72041,9 +72058,15 @@ var ts;
72041
72058
  if (!nonConstructorTypeInUnion)
72042
72059
  return type;
72043
72060
  }
72044
- return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom);
72061
+ return getNarrowedType(type, targetType, assumeTrue, /*checkDerived*/ true);
72062
+ }
72063
+ function getNarrowedType(type, candidate, assumeTrue, checkDerived) {
72064
+ var _a;
72065
+ var key = type.flags & 1048576 /* Union */ ? "N" + getTypeId(type) + "," + getTypeId(candidate) + "," + ((assumeTrue ? 1 : 0) | (checkDerived ? 2 : 0)) : undefined;
72066
+ return (_a = getCachedType(key)) !== null && _a !== void 0 ? _a : setCachedType(key, getNarrowedTypeWorker(type, candidate, assumeTrue, checkDerived));
72045
72067
  }
72046
- function getNarrowedType(type, candidate, assumeTrue, isRelated) {
72068
+ function getNarrowedTypeWorker(type, candidate, assumeTrue, checkDerived) {
72069
+ var isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf;
72047
72070
  if (!assumeTrue) {
72048
72071
  return filterType(type, function (t) { return !isRelated(t, candidate); });
72049
72072
  }
@@ -72091,7 +72114,7 @@ var ts;
72091
72114
  var predicateArgument = getTypePredicateArgument(predicate, callExpression);
72092
72115
  if (predicateArgument) {
72093
72116
  if (isMatchingReference(reference, predicateArgument)) {
72094
- return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
72117
+ return getNarrowedType(type, predicate.type, assumeTrue, /*checkDerived*/ false);
72095
72118
  }
72096
72119
  if (strictNullChecks && assumeTrue && optionalChainContainsReference(predicateArgument, reference) &&
72097
72120
  !(getTypeFacts(predicate.type) & 65536 /* EQUndefined */)) {
@@ -72099,7 +72122,7 @@ var ts;
72099
72122
  }
72100
72123
  var access = getDiscriminantPropertyAccess(predicateArgument, type);
72101
72124
  if (access) {
72102
- return narrowTypeByDiscriminant(type, access, function (t) { return getNarrowedType(t, predicate.type, assumeTrue, isTypeSubtypeOf); });
72125
+ return narrowTypeByDiscriminant(type, access, function (t) { return getNarrowedType(t, predicate.type, assumeTrue, /*checkDerived*/ false); });
72103
72126
  }
72104
72127
  }
72105
72128
  }
@@ -72438,9 +72461,7 @@ var ts;
72438
72461
  getNodeLinks(container).flags |= 8192 /* CaptureArguments */;
72439
72462
  return getTypeOfSymbol(symbol);
72440
72463
  }
72441
- // We should only mark aliases as referenced if there isn't a local value declaration
72442
- // for the symbol. Also, don't mark any property access expression LHS - checkPropertyAccessExpression will handle that
72443
- if (!(node.parent && ts.isPropertyAccessExpression(node.parent) && node.parent.expression === node)) {
72464
+ if (shouldMarkIdentifierAliasReferenced(node)) {
72444
72465
  markAliasReferenced(symbol, node);
72445
72466
  }
72446
72467
  var localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
@@ -72574,6 +72595,25 @@ var ts;
72574
72595
  }
72575
72596
  return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType;
72576
72597
  }
72598
+ function shouldMarkIdentifierAliasReferenced(node) {
72599
+ var _a;
72600
+ var parent = node.parent;
72601
+ if (parent) {
72602
+ // A property access expression LHS? checkPropertyAccessExpression will handle that.
72603
+ if (ts.isPropertyAccessExpression(parent) && parent.expression === node) {
72604
+ return false;
72605
+ }
72606
+ // Next two check for an identifier inside a type only export.
72607
+ if (ts.isExportSpecifier(parent) && parent.isTypeOnly) {
72608
+ return false;
72609
+ }
72610
+ var greatGrandparent = (_a = parent.parent) === null || _a === void 0 ? void 0 : _a.parent;
72611
+ if (greatGrandparent && ts.isExportDeclaration(greatGrandparent) && greatGrandparent.isTypeOnly) {
72612
+ return false;
72613
+ }
72614
+ }
72615
+ return true;
72616
+ }
72577
72617
  function isInsideFunctionOrInstancePropertyInitializer(node, threshold) {
72578
72618
  return !!ts.findAncestor(node, function (n) { return n === threshold ? "quit" : ts.isFunctionLike(n) || (n.parent && ts.isPropertyDeclaration(n.parent) && !ts.hasStaticModifier(n.parent) && n.parent.initializer === n); });
72579
72619
  }
@@ -77111,7 +77151,7 @@ var ts;
77111
77151
  argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
77112
77152
  if (inferenceContext) {
77113
77153
  var typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
77114
- checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
77154
+ checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext.inferredTypeParameters);
77115
77155
  // If the original signature has a generic rest type, instantiation may produce a
77116
77156
  // signature with different arity and we need to perform another arity check.
77117
77157
  if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
@@ -86383,7 +86423,9 @@ var ts;
86383
86423
  error(exportedName, ts.Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module, ts.idText(exportedName));
86384
86424
  }
86385
86425
  else {
86386
- markExportAsReferenced(node);
86426
+ if (!node.isTypeOnly && !node.parent.parent.isTypeOnly) {
86427
+ markExportAsReferenced(node);
86428
+ }
86387
86429
  var target = symbol && (symbol.flags & 2097152 /* Alias */ ? resolveAlias(symbol) : symbol);
86388
86430
  if (!target || target === unknownSymbol || target.flags & 111551 /* Value */) {
86389
86431
  checkExpressionCached(node.propertyName || node.name);
@@ -89744,9 +89786,6 @@ var ts;
89744
89786
  else {
89745
89787
  return grammarErrorOnNode(initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
89746
89788
  }
89747
- if (!isConstOrReadonly || isInvalidInitializer) {
89748
- return grammarErrorOnNode(initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
89749
- }
89750
89789
  }
89751
89790
  }
89752
89791
  function checkGrammarVariableDeclaration(node) {
@@ -111531,7 +111570,7 @@ var ts;
111531
111570
  return;
111532
111571
  }
111533
111572
  // Make sure not to write js file and source map file if any of them cannot be written
111534
- if ((jsFilePath && host.isEmitBlocked(jsFilePath)) || compilerOptions.noEmit) {
111573
+ if (host.isEmitBlocked(jsFilePath) || compilerOptions.noEmit) {
111535
111574
  emitSkipped = true;
111536
111575
  return;
111537
111576
  }
@@ -124793,7 +124832,6 @@ var ts;
124793
124832
  var parsedConfigs; // Parsed commandline and watching cached for referenced projects
124794
124833
  var sharedExtendedConfigFileWatchers; // Map of file watchers for extended files, shared between different referenced projects
124795
124834
  var extendedConfigCache = host.extendedConfigCache; // Cache for extended config evaluation
124796
- var changesAffectResolution = false; // Flag for indicating non-config changes affect module resolution
124797
124835
  var reportFileChangeDetectedOnCreateProgram = false; // True if synchronizeProgram should report "File change detected..." when a new program is created
124798
124836
  var sourceFilesCache = new ts.Map(); // Cache that stores the source file and version info
124799
124837
  var missingFilePathsRequestedForRelease; // These paths are held temporarily so that we can remove the entry from source file cache if the file is not tracked by missing files
@@ -124946,12 +124984,12 @@ var ts;
124946
124984
  var program = getCurrentBuilderProgram();
124947
124985
  if (hasChangedCompilerOptions) {
124948
124986
  newLine = updateNewLine();
124949
- if (program && (changesAffectResolution || ts.changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions))) {
124987
+ if (program && ts.changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions)) {
124950
124988
  resolutionCache.clear();
124951
124989
  }
124952
124990
  }
124953
124991
  // All resolutions are invalid if user provided resolutions
124954
- var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution || changesAffectResolution);
124992
+ var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution);
124955
124993
  if (ts.isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
124956
124994
  if (hasChangedConfigFileParsingErrors) {
124957
124995
  if (reportFileChangeDetectedOnCreateProgram) {
@@ -124967,7 +125005,6 @@ var ts;
124967
125005
  }
124968
125006
  createNewProgram(hasInvalidatedResolution);
124969
125007
  }
124970
- changesAffectResolution = false; // reset for next sync
124971
125008
  reportFileChangeDetectedOnCreateProgram = false;
124972
125009
  if (host.afterProgramCreate && program !== builderProgram) {
124973
125010
  host.afterProgramCreate(builderProgram);
@@ -126348,7 +126385,7 @@ var ts;
126348
126385
  }
126349
126386
  function afterProgramDone(state, program, config) {
126350
126387
  if (program) {
126351
- if (program && state.write)
126388
+ if (state.write)
126352
126389
  ts.listFiles(program, state.write);
126353
126390
  if (state.host.afterProgramEmitAndDiagnostics) {
126354
126391
  state.host.afterProgramEmitAndDiagnostics(program);
@@ -134536,7 +134573,7 @@ var ts;
134536
134573
  var name = ts.getSynthesizedDeepClone(ts.getNameOfDeclaration(declaration), /*includeTrivia*/ false);
134537
134574
  var type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
134538
134575
  var quotePreference = ts.getQuotePreference(sourceFile, preferences);
134539
- var builderFlags = quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : undefined;
134576
+ var builderFlags = 33554432 /* OmitThisParameter */ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */);
134540
134577
  switch (declaration.kind) {
134541
134578
  case 166 /* PropertySignature */:
134542
134579
  case 167 /* PropertyDeclaration */:
@@ -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.20220705";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220706";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -4726,6 +4726,7 @@ var ts;
4726
4726
  NodeBuilderFlags[NodeBuilderFlags["UseAliasDefinedOutsideCurrentScope"] = 16384] = "UseAliasDefinedOutsideCurrentScope";
4727
4727
  NodeBuilderFlags[NodeBuilderFlags["UseSingleQuotesForStringLiteralType"] = 268435456] = "UseSingleQuotesForStringLiteralType";
4728
4728
  NodeBuilderFlags[NodeBuilderFlags["NoTypeReduction"] = 536870912] = "NoTypeReduction";
4729
+ NodeBuilderFlags[NodeBuilderFlags["OmitThisParameter"] = 33554432] = "OmitThisParameter";
4729
4730
  // Error handling
4730
4731
  NodeBuilderFlags[NodeBuilderFlags["AllowThisInObjectLiteral"] = 32768] = "AllowThisInObjectLiteral";
4731
4732
  NodeBuilderFlags[NodeBuilderFlags["AllowQualifiedNameInPlaceOfIdentifier"] = 65536] = "AllowQualifiedNameInPlaceOfIdentifier";
@@ -4766,6 +4767,7 @@ var ts;
4766
4767
  TypeFormatFlags[TypeFormatFlags["UseAliasDefinedOutsideCurrentScope"] = 16384] = "UseAliasDefinedOutsideCurrentScope";
4767
4768
  TypeFormatFlags[TypeFormatFlags["UseSingleQuotesForStringLiteralType"] = 268435456] = "UseSingleQuotesForStringLiteralType";
4768
4769
  TypeFormatFlags[TypeFormatFlags["NoTypeReduction"] = 536870912] = "NoTypeReduction";
4770
+ TypeFormatFlags[TypeFormatFlags["OmitThisParameter"] = 33554432] = "OmitThisParameter";
4769
4771
  // Error Handling
4770
4772
  TypeFormatFlags[TypeFormatFlags["AllowUniqueESSymbolType"] = 1048576] = "AllowUniqueESSymbolType";
4771
4773
  // TypeFormatFlags exclusive
@@ -4777,7 +4779,7 @@ var ts;
4777
4779
  TypeFormatFlags[TypeFormatFlags["InFirstTypeArgument"] = 4194304] = "InFirstTypeArgument";
4778
4780
  TypeFormatFlags[TypeFormatFlags["InTypeAlias"] = 8388608] = "InTypeAlias";
4779
4781
  /** @deprecated */ TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 0] = "WriteOwnNameForAnyLike";
4780
- TypeFormatFlags[TypeFormatFlags["NodeBuilderFlagsMask"] = 814775659] = "NodeBuilderFlagsMask";
4782
+ TypeFormatFlags[TypeFormatFlags["NodeBuilderFlagsMask"] = 848330091] = "NodeBuilderFlagsMask";
4781
4783
  })(TypeFormatFlags = ts.TypeFormatFlags || (ts.TypeFormatFlags = {}));
4782
4784
  var SymbolFormatFlags;
4783
4785
  (function (SymbolFormatFlags) {
@@ -49088,6 +49090,7 @@ var ts;
49088
49090
  var stringMappingTypes = new ts.Map();
49089
49091
  var substitutionTypes = new ts.Map();
49090
49092
  var subtypeReductionCache = new ts.Map();
49093
+ var cachedTypes = new ts.Map();
49091
49094
  var evolvingArrayTypes = [];
49092
49095
  var undefinedProperties = new ts.Map();
49093
49096
  var markerTypes = new ts.Set();
@@ -49341,6 +49344,14 @@ var ts;
49341
49344
  ];
49342
49345
  initializeTypeChecker();
49343
49346
  return checker;
49347
+ function getCachedType(key) {
49348
+ return key ? cachedTypes.get(key) : undefined;
49349
+ }
49350
+ function setCachedType(key, type) {
49351
+ if (key)
49352
+ cachedTypes.set(key, type);
49353
+ return type;
49354
+ }
49344
49355
  function getJsxNamespace(location) {
49345
49356
  if (location) {
49346
49357
  var file = ts.getSourceFileOfNode(location);
@@ -52735,7 +52746,7 @@ var ts;
52735
52746
  }
52736
52747
  function toNodeBuilderFlags(flags) {
52737
52748
  if (flags === void 0) { flags = 0 /* None */; }
52738
- return flags & 814775659 /* NodeBuilderFlagsMask */;
52749
+ return flags & 848330091 /* NodeBuilderFlagsMask */;
52739
52750
  }
52740
52751
  function isClassInstanceSide(type) {
52741
52752
  return !!type.symbol && !!(type.symbol.flags & 32 /* Class */) && (type === getDeclaredTypeOfClassOrInterface(type.symbol) || (!!(type.flags & 524288 /* Object */) && !!(ts.getObjectFlags(type) & 16777216 /* IsClassInstanceClone */)));
@@ -53714,7 +53725,7 @@ var ts;
53714
53725
  var expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
53715
53726
  // If the expanded parameter list had a variadic in a non-trailing position, don't expand it
53716
53727
  var parameters = (ts.some(expandedParams, function (p) { return p !== expandedParams[expandedParams.length - 1] && !!(ts.getCheckFlags(p) & 32768 /* RestParameter */); }) ? signature.parameters : expandedParams).map(function (parameter) { return symbolToParameterDeclaration(parameter, context, kind === 171 /* Constructor */, options === null || options === void 0 ? void 0 : options.privateSymbolVisitor, options === null || options === void 0 ? void 0 : options.bundledImports); });
53717
- var thisParameter = tryGetThisParameterDeclaration(signature, context);
53728
+ var thisParameter = context.flags & 33554432 /* OmitThisParameter */ ? undefined : tryGetThisParameterDeclaration(signature, context);
53718
53729
  if (thisParameter) {
53719
53730
  parameters.unshift(thisParameter);
53720
53731
  }
@@ -54773,12 +54784,11 @@ var ts;
54773
54784
  if (skipMembershipCheck || (!!ts.length(symbol.declarations) && ts.some(symbol.declarations, function (d) { return !!ts.findAncestor(d, function (n) { return n === enclosingDeclaration; }); }))) {
54774
54785
  var oldContext = context;
54775
54786
  context = cloneNodeBuilderContext(context);
54776
- var result = serializeSymbolWorker(symbol, isPrivate, propertyAsAlias);
54787
+ serializeSymbolWorker(symbol, isPrivate, propertyAsAlias);
54777
54788
  if (context.reportedDiagnostic) {
54778
54789
  oldcontext.reportedDiagnostic = context.reportedDiagnostic; // hoist diagnostic result into outer context
54779
54790
  }
54780
54791
  context = oldContext;
54781
- return result;
54782
54792
  }
54783
54793
  }
54784
54794
  // Synthesize declarations for a symbol - might be an Interface, a Class, a Namespace, a Type, a Variable (const, let, or var), an Alias
@@ -57835,7 +57845,7 @@ var ts;
57835
57845
  error(declaration.typeExpression.type, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
57836
57846
  }
57837
57847
  else {
57838
- error(ts.isNamedDeclaration(declaration) ? declaration.name : declaration || declaration, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
57848
+ error(ts.isNamedDeclaration(declaration) ? declaration.name || declaration : declaration, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
57839
57849
  }
57840
57850
  }
57841
57851
  links.declaredType = type;
@@ -68018,9 +68028,14 @@ var ts;
68018
68028
  type.flags & 256 /* NumberLiteral */ ? numberType :
68019
68029
  type.flags & 2048 /* BigIntLiteral */ ? bigintType :
68020
68030
  type.flags & 512 /* BooleanLiteral */ ? booleanType :
68021
- type.flags & 1048576 /* Union */ ? mapType(type, getBaseTypeOfLiteralType) :
68031
+ type.flags & 1048576 /* Union */ ? getBaseTypeOfLiteralTypeUnion(type) :
68022
68032
  type;
68023
68033
  }
68034
+ function getBaseTypeOfLiteralTypeUnion(type) {
68035
+ var _a;
68036
+ var key = "B" + getTypeId(type);
68037
+ return (_a = getCachedType(key)) !== null && _a !== void 0 ? _a : setCachedType(key, mapType(type, getBaseTypeOfLiteralType));
68038
+ }
68024
68039
  function getWidenedLiteralType(type) {
68025
68040
  return type.flags & 1024 /* EnumLiteral */ && isFreshLiteralType(type) ? getBaseTypeOfEnumLiteralType(type) :
68026
68041
  type.flags & 128 /* StringLiteral */ && isFreshLiteralType(type) ? stringType :
@@ -70163,23 +70178,25 @@ var ts;
70163
70178
  // For example, when a variable of type number | string | boolean is assigned a value of type number | boolean,
70164
70179
  // we remove type string.
70165
70180
  function getAssignmentReducedType(declaredType, assignedType) {
70166
- if (declaredType !== assignedType) {
70167
- if (assignedType.flags & 131072 /* Never */) {
70168
- return assignedType;
70169
- }
70170
- var reducedType = filterType(declaredType, function (t) { return typeMaybeAssignableTo(assignedType, t); });
70171
- if (assignedType.flags & 512 /* BooleanLiteral */ && isFreshLiteralType(assignedType)) {
70172
- reducedType = mapType(reducedType, getFreshTypeOfLiteralType); // Ensure that if the assignment is a fresh type, that we narrow to fresh types
70173
- }
70174
- // Our crude heuristic produces an invalid result in some cases: see GH#26130.
70175
- // For now, when that happens, we give up and don't narrow at all. (This also
70176
- // means we'll never narrow for erroneous assignments where the assigned type
70177
- // is not assignable to the declared type.)
70178
- if (isTypeAssignableTo(assignedType, reducedType)) {
70179
- return reducedType;
70180
- }
70181
+ var _a;
70182
+ if (declaredType === assignedType) {
70183
+ return declaredType;
70181
70184
  }
70182
- return declaredType;
70185
+ if (assignedType.flags & 131072 /* Never */) {
70186
+ return assignedType;
70187
+ }
70188
+ var key = "A" + getTypeId(declaredType) + "," + getTypeId(assignedType);
70189
+ return (_a = getCachedType(key)) !== null && _a !== void 0 ? _a : setCachedType(key, getAssignmentReducedTypeWorker(declaredType, assignedType));
70190
+ }
70191
+ function getAssignmentReducedTypeWorker(declaredType, assignedType) {
70192
+ var filteredType = filterType(declaredType, function (t) { return typeMaybeAssignableTo(assignedType, t); });
70193
+ // Ensure that we narrow to fresh types if the assignment is a fresh boolean literal type.
70194
+ var reducedType = assignedType.flags & 512 /* BooleanLiteral */ && isFreshLiteralType(assignedType) ? mapType(filteredType, getFreshTypeOfLiteralType) : filteredType;
70195
+ // Our crude heuristic produces an invalid result in some cases: see GH#26130.
70196
+ // For now, when that happens, we give up and don't narrow at all. (This also
70197
+ // means we'll never narrow for erroneous assignments where the assigned type
70198
+ // is not assignable to the declared type.)
70199
+ return isTypeAssignableTo(assignedType, reducedType) ? reducedType : declaredType;
70183
70200
  }
70184
70201
  function isFunctionObjectType(type) {
70185
70202
  // We do a quick check for a "bind" property before performing the more expensive subtype
@@ -71585,7 +71602,7 @@ var ts;
71585
71602
  var targetType = ts.hasStaticModifier(ts.Debug.checkDefined(symbol.valueDeclaration, "should always have a declaration"))
71586
71603
  ? getTypeOfSymbol(classSymbol)
71587
71604
  : getDeclaredTypeOfSymbol(classSymbol);
71588
- return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom);
71605
+ return getNarrowedType(type, targetType, assumeTrue, /*checkDerived*/ true);
71589
71606
  }
71590
71607
  function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) {
71591
71608
  // We are in a branch of obj?.foo === value (or any one of the other equality operators). We narrow obj as follows:
@@ -71836,9 +71853,15 @@ var ts;
71836
71853
  if (!nonConstructorTypeInUnion)
71837
71854
  return type;
71838
71855
  }
71839
- return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom);
71856
+ return getNarrowedType(type, targetType, assumeTrue, /*checkDerived*/ true);
71857
+ }
71858
+ function getNarrowedType(type, candidate, assumeTrue, checkDerived) {
71859
+ var _a;
71860
+ var key = type.flags & 1048576 /* Union */ ? "N" + getTypeId(type) + "," + getTypeId(candidate) + "," + ((assumeTrue ? 1 : 0) | (checkDerived ? 2 : 0)) : undefined;
71861
+ return (_a = getCachedType(key)) !== null && _a !== void 0 ? _a : setCachedType(key, getNarrowedTypeWorker(type, candidate, assumeTrue, checkDerived));
71840
71862
  }
71841
- function getNarrowedType(type, candidate, assumeTrue, isRelated) {
71863
+ function getNarrowedTypeWorker(type, candidate, assumeTrue, checkDerived) {
71864
+ var isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf;
71842
71865
  if (!assumeTrue) {
71843
71866
  return filterType(type, function (t) { return !isRelated(t, candidate); });
71844
71867
  }
@@ -71886,7 +71909,7 @@ var ts;
71886
71909
  var predicateArgument = getTypePredicateArgument(predicate, callExpression);
71887
71910
  if (predicateArgument) {
71888
71911
  if (isMatchingReference(reference, predicateArgument)) {
71889
- return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
71912
+ return getNarrowedType(type, predicate.type, assumeTrue, /*checkDerived*/ false);
71890
71913
  }
71891
71914
  if (strictNullChecks && assumeTrue && optionalChainContainsReference(predicateArgument, reference) &&
71892
71915
  !(getTypeFacts(predicate.type) & 65536 /* EQUndefined */)) {
@@ -71894,7 +71917,7 @@ var ts;
71894
71917
  }
71895
71918
  var access = getDiscriminantPropertyAccess(predicateArgument, type);
71896
71919
  if (access) {
71897
- return narrowTypeByDiscriminant(type, access, function (t) { return getNarrowedType(t, predicate.type, assumeTrue, isTypeSubtypeOf); });
71920
+ return narrowTypeByDiscriminant(type, access, function (t) { return getNarrowedType(t, predicate.type, assumeTrue, /*checkDerived*/ false); });
71898
71921
  }
71899
71922
  }
71900
71923
  }
@@ -72233,9 +72256,7 @@ var ts;
72233
72256
  getNodeLinks(container).flags |= 8192 /* CaptureArguments */;
72234
72257
  return getTypeOfSymbol(symbol);
72235
72258
  }
72236
- // We should only mark aliases as referenced if there isn't a local value declaration
72237
- // for the symbol. Also, don't mark any property access expression LHS - checkPropertyAccessExpression will handle that
72238
- if (!(node.parent && ts.isPropertyAccessExpression(node.parent) && node.parent.expression === node)) {
72259
+ if (shouldMarkIdentifierAliasReferenced(node)) {
72239
72260
  markAliasReferenced(symbol, node);
72240
72261
  }
72241
72262
  var localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
@@ -72369,6 +72390,25 @@ var ts;
72369
72390
  }
72370
72391
  return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType;
72371
72392
  }
72393
+ function shouldMarkIdentifierAliasReferenced(node) {
72394
+ var _a;
72395
+ var parent = node.parent;
72396
+ if (parent) {
72397
+ // A property access expression LHS? checkPropertyAccessExpression will handle that.
72398
+ if (ts.isPropertyAccessExpression(parent) && parent.expression === node) {
72399
+ return false;
72400
+ }
72401
+ // Next two check for an identifier inside a type only export.
72402
+ if (ts.isExportSpecifier(parent) && parent.isTypeOnly) {
72403
+ return false;
72404
+ }
72405
+ var greatGrandparent = (_a = parent.parent) === null || _a === void 0 ? void 0 : _a.parent;
72406
+ if (greatGrandparent && ts.isExportDeclaration(greatGrandparent) && greatGrandparent.isTypeOnly) {
72407
+ return false;
72408
+ }
72409
+ }
72410
+ return true;
72411
+ }
72372
72412
  function isInsideFunctionOrInstancePropertyInitializer(node, threshold) {
72373
72413
  return !!ts.findAncestor(node, function (n) { return n === threshold ? "quit" : ts.isFunctionLike(n) || (n.parent && ts.isPropertyDeclaration(n.parent) && !ts.hasStaticModifier(n.parent) && n.parent.initializer === n); });
72374
72414
  }
@@ -76906,7 +76946,7 @@ var ts;
76906
76946
  argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
76907
76947
  if (inferenceContext) {
76908
76948
  var typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
76909
- checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
76949
+ checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext.inferredTypeParameters);
76910
76950
  // If the original signature has a generic rest type, instantiation may produce a
76911
76951
  // signature with different arity and we need to perform another arity check.
76912
76952
  if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
@@ -86178,7 +86218,9 @@ var ts;
86178
86218
  error(exportedName, ts.Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module, ts.idText(exportedName));
86179
86219
  }
86180
86220
  else {
86181
- markExportAsReferenced(node);
86221
+ if (!node.isTypeOnly && !node.parent.parent.isTypeOnly) {
86222
+ markExportAsReferenced(node);
86223
+ }
86182
86224
  var target = symbol && (symbol.flags & 2097152 /* Alias */ ? resolveAlias(symbol) : symbol);
86183
86225
  if (!target || target === unknownSymbol || target.flags & 111551 /* Value */) {
86184
86226
  checkExpressionCached(node.propertyName || node.name);
@@ -89539,9 +89581,6 @@ var ts;
89539
89581
  else {
89540
89582
  return grammarErrorOnNode(initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
89541
89583
  }
89542
- if (!isConstOrReadonly || isInvalidInitializer) {
89543
- return grammarErrorOnNode(initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
89544
- }
89545
89584
  }
89546
89585
  }
89547
89586
  function checkGrammarVariableDeclaration(node) {
@@ -111326,7 +111365,7 @@ var ts;
111326
111365
  return;
111327
111366
  }
111328
111367
  // Make sure not to write js file and source map file if any of them cannot be written
111329
- if ((jsFilePath && host.isEmitBlocked(jsFilePath)) || compilerOptions.noEmit) {
111368
+ if (host.isEmitBlocked(jsFilePath) || compilerOptions.noEmit) {
111330
111369
  emitSkipped = true;
111331
111370
  return;
111332
111371
  }
@@ -124588,7 +124627,6 @@ var ts;
124588
124627
  var parsedConfigs; // Parsed commandline and watching cached for referenced projects
124589
124628
  var sharedExtendedConfigFileWatchers; // Map of file watchers for extended files, shared between different referenced projects
124590
124629
  var extendedConfigCache = host.extendedConfigCache; // Cache for extended config evaluation
124591
- var changesAffectResolution = false; // Flag for indicating non-config changes affect module resolution
124592
124630
  var reportFileChangeDetectedOnCreateProgram = false; // True if synchronizeProgram should report "File change detected..." when a new program is created
124593
124631
  var sourceFilesCache = new ts.Map(); // Cache that stores the source file and version info
124594
124632
  var missingFilePathsRequestedForRelease; // These paths are held temporarily so that we can remove the entry from source file cache if the file is not tracked by missing files
@@ -124741,12 +124779,12 @@ var ts;
124741
124779
  var program = getCurrentBuilderProgram();
124742
124780
  if (hasChangedCompilerOptions) {
124743
124781
  newLine = updateNewLine();
124744
- if (program && (changesAffectResolution || ts.changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions))) {
124782
+ if (program && ts.changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions)) {
124745
124783
  resolutionCache.clear();
124746
124784
  }
124747
124785
  }
124748
124786
  // All resolutions are invalid if user provided resolutions
124749
- var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution || changesAffectResolution);
124787
+ var hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution);
124750
124788
  if (ts.isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
124751
124789
  if (hasChangedConfigFileParsingErrors) {
124752
124790
  if (reportFileChangeDetectedOnCreateProgram) {
@@ -124762,7 +124800,6 @@ var ts;
124762
124800
  }
124763
124801
  createNewProgram(hasInvalidatedResolution);
124764
124802
  }
124765
- changesAffectResolution = false; // reset for next sync
124766
124803
  reportFileChangeDetectedOnCreateProgram = false;
124767
124804
  if (host.afterProgramCreate && program !== builderProgram) {
124768
124805
  host.afterProgramCreate(builderProgram);
@@ -126143,7 +126180,7 @@ var ts;
126143
126180
  }
126144
126181
  function afterProgramDone(state, program, config) {
126145
126182
  if (program) {
126146
- if (program && state.write)
126183
+ if (state.write)
126147
126184
  ts.listFiles(program, state.write);
126148
126185
  if (state.host.afterProgramEmitAndDiagnostics) {
126149
126186
  state.host.afterProgramEmitAndDiagnostics(program);