typescript 4.6.0-dev.20211203 → 4.6.0-dev.20211204

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.20211203";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20211204";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -1037,7 +1037,11 @@ var ts;
1037
1037
  }
1038
1038
  return deduplicated;
1039
1039
  }
1040
- function insertSorted(array, insert, compare) {
1040
+ function createSortedArray() {
1041
+ return []; // TODO: GH#19873
1042
+ }
1043
+ ts.createSortedArray = createSortedArray;
1044
+ function insertSorted(array, insert, compare, allowDuplicates) {
1041
1045
  if (array.length === 0) {
1042
1046
  array.push(insert);
1043
1047
  return;
@@ -1046,6 +1050,9 @@ var ts;
1046
1050
  if (insertIndex < 0) {
1047
1051
  array.splice(~insertIndex, 0, insert);
1048
1052
  }
1053
+ else if (allowDuplicates) {
1054
+ array.splice(insertIndex, 0, insert);
1055
+ }
1049
1056
  }
1050
1057
  ts.insertSorted = insertSorted;
1051
1058
  function sortAndDeduplicate(array, comparer, equalityComparer) {
@@ -8411,6 +8418,7 @@ var ts;
8411
8418
  Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity: diag(2308, ts.DiagnosticCategory.Error, "Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambig_2308", "Module {0} has already exported a member named '{1}'. Consider explicitly re-exporting to resolve the ambiguity."),
8412
8419
  An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: diag(2309, ts.DiagnosticCategory.Error, "An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements_2309", "An export assignment cannot be used in a module with other exported elements."),
8413
8420
  Type_0_recursively_references_itself_as_a_base_type: diag(2310, ts.DiagnosticCategory.Error, "Type_0_recursively_references_itself_as_a_base_type_2310", "Type '{0}' recursively references itself as a base type."),
8421
+ Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function: diag(2311, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function_2311", "Cannot find name '{0}'. Did you mean to write this in an async function?"),
8414
8422
  An_interface_can_only_extend_an_object_type_or_intersection_of_object_types_with_statically_known_members: diag(2312, ts.DiagnosticCategory.Error, "An_interface_can_only_extend_an_object_type_or_intersection_of_object_types_with_statically_known_me_2312", "An interface can only extend an object type or intersection of object types with statically known members."),
8415
8423
  Type_parameter_0_has_a_circular_constraint: diag(2313, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_constraint_2313", "Type parameter '{0}' has a circular constraint."),
8416
8424
  Generic_type_0_requires_1_type_argument_s: diag(2314, ts.DiagnosticCategory.Error, "Generic_type_0_requires_1_type_argument_s_2314", "Generic type '{0}' requires {1} type argument(s)."),
@@ -20952,6 +20960,10 @@ var ts;
20952
20960
  return text.replace(/\$/gm, "\\$");
20953
20961
  }
20954
20962
  ts.escapeSnippetText = escapeSnippetText;
20963
+ function isThisTypeParameter(type) {
20964
+ return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
20965
+ }
20966
+ ts.isThisTypeParameter = isThisTypeParameter;
20955
20967
  })(ts || (ts = {}));
20956
20968
  /* @internal */
20957
20969
  var ts;
@@ -47034,6 +47046,7 @@ var ts;
47034
47046
  getIndexInfosOfType: getIndexInfosOfType,
47035
47047
  getSignaturesOfType: getSignaturesOfType,
47036
47048
  getIndexTypeOfType: function (type, kind) { return getIndexTypeOfType(type, kind === 0 /* String */ ? stringType : numberType); },
47049
+ getIndexType: function (type) { return getIndexType(type); },
47037
47050
  getBaseTypes: getBaseTypes,
47038
47051
  getBaseTypeOfLiteralType: getBaseTypeOfLiteralType,
47039
47052
  getWidenedType: getWidenedType,
@@ -48291,11 +48304,12 @@ var ts;
48291
48304
  *
48292
48305
  * @param isUse If true, this will count towards --noUnusedLocals / --noUnusedParameters.
48293
48306
  */
48294
- function resolveName(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals) {
48307
+ function resolveName(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions) {
48295
48308
  if (excludeGlobals === void 0) { excludeGlobals = false; }
48296
- return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
48309
+ if (getSpellingSuggstions === void 0) { getSpellingSuggstions = true; }
48310
+ return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions, getSymbol);
48297
48311
  }
48298
- function resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, lookup) {
48312
+ function resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, lookup) {
48299
48313
  var _a, _b, _c;
48300
48314
  var originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
48301
48315
  var result;
@@ -48612,7 +48626,7 @@ var ts;
48612
48626
  }
48613
48627
  }
48614
48628
  if (!result) {
48615
- if (nameNotFoundMessage) {
48629
+ if (nameNotFoundMessage && produceDiagnostics) {
48616
48630
  if (!errorLocation ||
48617
48631
  !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
48618
48632
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -48622,7 +48636,7 @@ var ts;
48622
48636
  !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
48623
48637
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
48624
48638
  var suggestion = void 0;
48625
- if (suggestionCount < maximumSuggestionCount) {
48639
+ if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
48626
48640
  suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
48627
48641
  var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
48628
48642
  if (isGlobalScopeAugmentationDeclaration) {
@@ -48658,7 +48672,7 @@ var ts;
48658
48672
  return undefined;
48659
48673
  }
48660
48674
  // Perform extra checks only if error reporting was requested
48661
- if (nameNotFoundMessage) {
48675
+ if (nameNotFoundMessage && produceDiagnostics) {
48662
48676
  if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
48663
48677
  // We have a match, but the reference occurred within a property initializer and the identifier also binds
48664
48678
  // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
@@ -51134,7 +51148,7 @@ var ts;
51134
51148
  context.approximateLength += 6;
51135
51149
  return ts.factory.createKeywordTypeNode(147 /* ObjectKeyword */);
51136
51150
  }
51137
- if (isThisTypeParameter(type)) {
51151
+ if (ts.isThisTypeParameter(type)) {
51138
51152
  if (context.flags & 4194304 /* InObjectTypeLiteral */) {
51139
51153
  if (!context.encounteredError && !(context.flags & 32768 /* AllowThisInObjectLiteral */)) {
51140
51154
  context.encounteredError = true;
@@ -59079,7 +59093,7 @@ var ts;
59079
59093
  }
59080
59094
  function getGlobalSymbol(name, meaning, diagnostic) {
59081
59095
  // Don't track references for global symbols anyway, so value if `isReference` is arbitrary
59082
- return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false);
59096
+ return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ false);
59083
59097
  }
59084
59098
  function getGlobalType(name, arity, reportErrors) {
59085
59099
  var symbol = getGlobalTypeSymbol(name, reportErrors);
@@ -60658,9 +60672,6 @@ var ts;
60658
60672
  return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 8388608 /* IsGenericObjectType */ : 0) |
60659
60673
  (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 16777216 /* IsGenericIndexType */ : 0);
60660
60674
  }
60661
- function isThisTypeParameter(type) {
60662
- return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
60663
- }
60664
60675
  function getSimplifiedType(type, writing) {
60665
60676
  return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) :
60666
60677
  type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) :
@@ -65858,7 +65869,7 @@ var ts;
65858
65869
  // flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
65859
65870
  // no flags for all other types (including non-falsy literal types).
65860
65871
  function getFalsyFlags(type) {
65861
- return type.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(type.types) :
65872
+ return type.flags & 3145728 /* UnionOrIntersection */ ? getFalsyFlagsOfTypes(type.types) :
65862
65873
  type.flags & 128 /* StringLiteral */ ? type.value === "" ? 128 /* StringLiteral */ : 0 :
65863
65874
  type.flags & 256 /* NumberLiteral */ ? type.value === 0 ? 256 /* NumberLiteral */ : 0 :
65864
65875
  type.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(type) ? 2048 /* BigIntLiteral */ : 0 :
@@ -67474,6 +67485,11 @@ var ts;
67474
67485
  case "BigInt64Array":
67475
67486
  case "BigUint64Array":
67476
67487
  return ts.Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_1_or_later;
67488
+ case "await":
67489
+ if (ts.isCallExpression(node.parent)) {
67490
+ return ts.Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function;
67491
+ }
67492
+ // falls through
67477
67493
  default:
67478
67494
  if (node.parent.kind === 295 /* ShorthandPropertyAssignment */) {
67479
67495
  return ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer;
@@ -69031,7 +69047,7 @@ var ts;
69031
69047
  function narrowByInKeyword(type, name, assumeTrue) {
69032
69048
  if (type.flags & 1048576 /* Union */
69033
69049
  || type.flags & 524288 /* Object */ && declaredType !== type
69034
- || isThisTypeParameter(type)
69050
+ || ts.isThisTypeParameter(type)
69035
69051
  || type.flags & 2097152 /* Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) {
69036
69052
  return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); });
69037
69053
  }
@@ -71851,15 +71867,9 @@ var ts;
71851
71867
  }
71852
71868
  }
71853
71869
  function isValidSpreadType(type) {
71854
- if (type.flags & 465829888 /* Instantiable */) {
71855
- var constraint = getBaseConstraintOfType(type);
71856
- if (constraint !== undefined) {
71857
- return isValidSpreadType(constraint);
71858
- }
71859
- }
71860
- return !!(type.flags & (1 /* Any */ | 67108864 /* NonPrimitive */ | 524288 /* Object */ | 58982400 /* InstantiableNonPrimitive */) ||
71861
- getFalsyFlags(type) & 117632 /* DefinitelyFalsy */ && isValidSpreadType(removeDefinitelyFalsyTypes(type)) ||
71862
- type.flags & 3145728 /* UnionOrIntersection */ && ts.every(type.types, isValidSpreadType));
71870
+ var t = removeDefinitelyFalsyTypes(mapType(type, getBaseConstraintOrType));
71871
+ return !!(t.flags & (1 /* Any */ | 67108864 /* NonPrimitive */ | 524288 /* Object */ | 58982400 /* InstantiableNonPrimitive */) ||
71872
+ t.flags & 3145728 /* UnionOrIntersection */ && ts.every(t.types, isValidSpreadType));
71863
71873
  }
71864
71874
  function checkJsxSelfClosingElementDeferred(node) {
71865
71875
  checkJsxOpeningLikeElementOrOpeningFragment(node);
@@ -72810,7 +72820,7 @@ var ts;
72810
72820
  }
72811
72821
  var propType;
72812
72822
  if (!prop) {
72813
- var indexInfo = !ts.isPrivateIdentifier(right) && (assignmentKind === 0 /* None */ || !isGenericObjectType(leftType) || isThisTypeParameter(leftType)) ?
72823
+ var indexInfo = !ts.isPrivateIdentifier(right) && (assignmentKind === 0 /* None */ || !isGenericObjectType(leftType) || ts.isThisTypeParameter(leftType)) ?
72814
72824
  getApplicableIndexInfoForName(apparentType, right.escapedText) : undefined;
72815
72825
  if (!(indexInfo && indexInfo.type)) {
72816
72826
  var isUncheckedJS = isUncheckedJSSuggestion(node, leftType.symbol, /*excludeClasses*/ true);
@@ -72827,7 +72837,7 @@ var ts;
72827
72837
  return anyType;
72828
72838
  }
72829
72839
  if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) {
72830
- reportNonexistentProperty(right, isThisTypeParameter(leftType) ? apparentType : leftType, isUncheckedJS);
72840
+ reportNonexistentProperty(right, ts.isThisTypeParameter(leftType) ? apparentType : leftType, isUncheckedJS);
72831
72841
  }
72832
72842
  return errorType;
72833
72843
  }
@@ -73120,7 +73130,7 @@ var ts;
73120
73130
  }
73121
73131
  function getSuggestedSymbolForNonexistentSymbol(location, outerName, meaning) {
73122
73132
  ts.Debug.assert(outerName !== undefined, "outername should always be defined");
73123
- var result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, function (symbols, name, meaning) {
73133
+ var result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ true, function (symbols, name, meaning) {
73124
73134
  ts.Debug.assertEqual(outerName, name, "name should equal outerName");
73125
73135
  var symbol = getSymbol(symbols, name, meaning);
73126
73136
  // Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
@@ -73366,7 +73376,7 @@ var ts;
73366
73376
  }
73367
73377
  var effectiveIndexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : indexType;
73368
73378
  var accessFlags = ts.isAssignmentTarget(node) ?
73369
- 4 /* Writing */ | (isGenericObjectType(objectType) && !isThisTypeParameter(objectType) ? 2 /* NoIndexSignatures */ : 0) :
73379
+ 4 /* Writing */ | (isGenericObjectType(objectType) && !ts.isThisTypeParameter(objectType) ? 2 /* NoIndexSignatures */ : 0) :
73370
73380
  32 /* ExpressionPosition */;
73371
73381
  var indexedAccessType = getIndexedAccessTypeOrUndefined(objectType, effectiveIndexType, accessFlags, node) || errorType;
73372
73382
  return checkIndexedAccessIndexType(getFlowTypeOfAccessExpression(node, getNodeLinks(node).resolvedSymbol, indexedAccessType, indexExpression, checkMode), node);
@@ -128197,7 +128207,7 @@ var ts;
128197
128207
  case 0 /* Paths */:
128198
128208
  return convertPathCompletions(completion.paths);
128199
128209
  case 1 /* Properties */: {
128200
- var entries = [];
128210
+ var entries = ts.createSortedArray();
128201
128211
  Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, host, program, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
128202
128212
  return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
128203
128213
  }
@@ -128395,7 +128405,7 @@ var ts;
128395
128405
  var types = ts.flatMap(candidates, function (candidate) {
128396
128406
  if (!ts.signatureHasRestParameter(candidate) && argumentInfo.argumentCount > candidate.parameters.length)
128397
128407
  return;
128398
- var type = checker.getParameterType(candidate, argumentInfo.argumentIndex);
128408
+ var type = candidate.getTypeParameterAtPosition(argumentInfo.argumentIndex);
128399
128409
  isNewIdentifier = isNewIdentifier || !!(type.flags & 4 /* String */);
128400
128410
  return getStringLiteralTypes(type, uniques);
128401
128411
  });
@@ -129079,6 +129089,29 @@ var ts;
129079
129089
  }
129080
129090
  }
129081
129091
  Completions.getCompletionsAtPosition = getCompletionsAtPosition;
129092
+ // Editors will use the `sortText` and then fall back to `name` for sorting, but leave ties in response order.
129093
+ // So, it's important that we sort those ties in the order we want them displayed if it matters. We don't
129094
+ // strictly need to sort by name or SortText here since clients are going to do it anyway, but we have to
129095
+ // do the work of comparing them so we can sort those ties appropriately; plus, it makes the order returned
129096
+ // by the language service consistent with what TS Server does and what editors typically do. This also makes
129097
+ // completions tests make more sense. We used to sort only alphabetically and only in the server layer, but
129098
+ // this made tests really weird, since most fourslash tests don't use the server.
129099
+ function compareCompletionEntries(entryInArray, entryToInsert) {
129100
+ var _a, _b;
129101
+ var result = ts.compareStringsCaseSensitiveUI(entryInArray.sortText, entryToInsert.sortText);
129102
+ if (result === 0 /* EqualTo */) {
129103
+ result = ts.compareStringsCaseSensitiveUI(entryInArray.name, entryToInsert.name);
129104
+ }
129105
+ if (result === 0 /* EqualTo */ && ((_a = entryInArray.data) === null || _a === void 0 ? void 0 : _a.moduleSpecifier) && ((_b = entryToInsert.data) === null || _b === void 0 ? void 0 : _b.moduleSpecifier)) {
129106
+ // Sort same-named auto-imports by module specifier
129107
+ result = ts.compareNumberOfDirectorySeparators(entryInArray.data.moduleSpecifier, entryToInsert.data.moduleSpecifier);
129108
+ }
129109
+ if (result === 0 /* EqualTo */) {
129110
+ // Fall back to symbol order - if we return `EqualTo`, `insertSorted` will put later symbols first.
129111
+ return -1 /* LessThan */;
129112
+ }
129113
+ return result;
129114
+ }
129082
129115
  function completionEntryDataIsResolved(data) {
129083
129116
  return !!(data === null || data === void 0 ? void 0 : data.moduleSpecifier);
129084
129117
  }
@@ -129165,7 +129198,7 @@ var ts;
129165
129198
  return completionInfo;
129166
129199
  }
129167
129200
  }
129168
- var entries = [];
129201
+ var entries = ts.createSortedArray();
129169
129202
  if (isUncheckedFile(sourceFile, compilerOptions)) {
129170
129203
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
129171
129204
  /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
@@ -129183,13 +129216,13 @@ var ts;
129183
129216
  for (var _i = 0, _a = getKeywordCompletions(keywordFilters, !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile)); _i < _a.length; _i++) {
129184
129217
  var keywordEntry = _a[_i];
129185
129218
  if (!entryNames.has(keywordEntry.name)) {
129186
- entries.push(keywordEntry);
129219
+ ts.insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
129187
129220
  }
129188
129221
  }
129189
129222
  }
129190
129223
  for (var _b = 0, literals_1 = literals; _b < literals_1.length; _b++) {
129191
129224
  var literal = literals_1[_b];
129192
- entries.push(createCompletionEntryForLiteral(sourceFile, preferences, literal));
129225
+ ts.insertSorted(entries, createCompletionEntryForLiteral(sourceFile, preferences, literal), compareCompletionEntries, /*allowDuplicates*/ true);
129193
129226
  }
129194
129227
  return {
129195
129228
  isGlobalCompletion: isInSnippetScope,
@@ -129265,13 +129298,13 @@ var ts;
129265
129298
  var realName = ts.unescapeLeadingUnderscores(name);
129266
129299
  if (!uniqueNames.has(realName) && ts.isIdentifierText(realName, target)) {
129267
129300
  uniqueNames.add(realName);
129268
- entries.push({
129301
+ ts.insertSorted(entries, {
129269
129302
  name: realName,
129270
129303
  kind: "warning" /* warning */,
129271
129304
  kindModifiers: "",
129272
129305
  sortText: SortText.JavascriptIdentifiers,
129273
129306
  isFromUncheckedFile: true
129274
- });
129307
+ }, compareCompletionEntries);
129275
129308
  }
129276
129309
  });
129277
129310
  }
@@ -129695,7 +129728,7 @@ var ts;
129695
129728
  /** True for locals; false for globals, module exports from other files, `this.` completions. */
129696
129729
  var shouldShadowLaterSymbols = !origin && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
129697
129730
  uniques.set(name, shouldShadowLaterSymbols);
129698
- entries.push(entry);
129731
+ ts.insertSorted(entries, entry, compareCompletionEntries, /*allowDuplicates*/ true);
129699
129732
  }
129700
129733
  log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (ts.timestamp() - start));
129701
129734
  // Prevent consumers of this map from having to worry about
@@ -152172,6 +152205,7 @@ var ts;
152172
152205
  var errorCodes = [
152173
152206
  ts.Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
152174
152207
  ts.Diagnostics.for_await_loops_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
152208
+ ts.Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function.code
152175
152209
  ];
152176
152210
  codefix.registerCodeFix({
152177
152211
  errorCodes: errorCodes,
@@ -159982,6 +160016,9 @@ var ts;
159982
160016
  TypeObject.prototype.isClass = function () {
159983
160017
  return !!(ts.getObjectFlags(this) & 1 /* Class */);
159984
160018
  };
160019
+ TypeObject.prototype.isIndexType = function () {
160020
+ return !!(this.flags & 4194304 /* Index */);
160021
+ };
159985
160022
  Object.defineProperty(TypeObject.prototype, "typeArguments", {
159986
160023
  /**
159987
160024
  * This polyfills `referenceType.typeArguments` for API consumers
@@ -160014,6 +160051,16 @@ var ts;
160014
160051
  SignatureObject.prototype.getReturnType = function () {
160015
160052
  return this.checker.getReturnTypeOfSignature(this);
160016
160053
  };
160054
+ SignatureObject.prototype.getTypeParameterAtPosition = function (pos) {
160055
+ var type = this.checker.getParameterType(this, pos);
160056
+ if (type.isIndexType() && ts.isThisTypeParameter(type.type)) {
160057
+ var constraint = type.type.getConstraint();
160058
+ if (constraint) {
160059
+ return this.checker.getIndexType(constraint);
160060
+ }
160061
+ }
160062
+ return type;
160063
+ };
160017
160064
  SignatureObject.prototype.getDocumentationComment = function () {
160018
160065
  return this.documentationComment || (this.documentationComment = getDocumentationComment(ts.singleElementArray(this.declaration), this.checker));
160019
160066
  };
@@ -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.20211203";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20211204";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -832,7 +832,11 @@ var ts;
832
832
  }
833
833
  return deduplicated;
834
834
  }
835
- function insertSorted(array, insert, compare) {
835
+ function createSortedArray() {
836
+ return []; // TODO: GH#19873
837
+ }
838
+ ts.createSortedArray = createSortedArray;
839
+ function insertSorted(array, insert, compare, allowDuplicates) {
836
840
  if (array.length === 0) {
837
841
  array.push(insert);
838
842
  return;
@@ -841,6 +845,9 @@ var ts;
841
845
  if (insertIndex < 0) {
842
846
  array.splice(~insertIndex, 0, insert);
843
847
  }
848
+ else if (allowDuplicates) {
849
+ array.splice(insertIndex, 0, insert);
850
+ }
844
851
  }
845
852
  ts.insertSorted = insertSorted;
846
853
  function sortAndDeduplicate(array, comparer, equalityComparer) {
@@ -8206,6 +8213,7 @@ var ts;
8206
8213
  Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity: diag(2308, ts.DiagnosticCategory.Error, "Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambig_2308", "Module {0} has already exported a member named '{1}'. Consider explicitly re-exporting to resolve the ambiguity."),
8207
8214
  An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: diag(2309, ts.DiagnosticCategory.Error, "An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements_2309", "An export assignment cannot be used in a module with other exported elements."),
8208
8215
  Type_0_recursively_references_itself_as_a_base_type: diag(2310, ts.DiagnosticCategory.Error, "Type_0_recursively_references_itself_as_a_base_type_2310", "Type '{0}' recursively references itself as a base type."),
8216
+ Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function: diag(2311, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function_2311", "Cannot find name '{0}'. Did you mean to write this in an async function?"),
8209
8217
  An_interface_can_only_extend_an_object_type_or_intersection_of_object_types_with_statically_known_members: diag(2312, ts.DiagnosticCategory.Error, "An_interface_can_only_extend_an_object_type_or_intersection_of_object_types_with_statically_known_me_2312", "An interface can only extend an object type or intersection of object types with statically known members."),
8210
8218
  Type_parameter_0_has_a_circular_constraint: diag(2313, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_constraint_2313", "Type parameter '{0}' has a circular constraint."),
8211
8219
  Generic_type_0_requires_1_type_argument_s: diag(2314, ts.DiagnosticCategory.Error, "Generic_type_0_requires_1_type_argument_s_2314", "Generic type '{0}' requires {1} type argument(s)."),
@@ -20747,6 +20755,10 @@ var ts;
20747
20755
  return text.replace(/\$/gm, "\\$");
20748
20756
  }
20749
20757
  ts.escapeSnippetText = escapeSnippetText;
20758
+ function isThisTypeParameter(type) {
20759
+ return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
20760
+ }
20761
+ ts.isThisTypeParameter = isThisTypeParameter;
20750
20762
  })(ts || (ts = {}));
20751
20763
  /* @internal */
20752
20764
  var ts;
@@ -46829,6 +46841,7 @@ var ts;
46829
46841
  getIndexInfosOfType: getIndexInfosOfType,
46830
46842
  getSignaturesOfType: getSignaturesOfType,
46831
46843
  getIndexTypeOfType: function (type, kind) { return getIndexTypeOfType(type, kind === 0 /* String */ ? stringType : numberType); },
46844
+ getIndexType: function (type) { return getIndexType(type); },
46832
46845
  getBaseTypes: getBaseTypes,
46833
46846
  getBaseTypeOfLiteralType: getBaseTypeOfLiteralType,
46834
46847
  getWidenedType: getWidenedType,
@@ -48086,11 +48099,12 @@ var ts;
48086
48099
  *
48087
48100
  * @param isUse If true, this will count towards --noUnusedLocals / --noUnusedParameters.
48088
48101
  */
48089
- function resolveName(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals) {
48102
+ function resolveName(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions) {
48090
48103
  if (excludeGlobals === void 0) { excludeGlobals = false; }
48091
- return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
48104
+ if (getSpellingSuggstions === void 0) { getSpellingSuggstions = true; }
48105
+ return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions, getSymbol);
48092
48106
  }
48093
- function resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, lookup) {
48107
+ function resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, lookup) {
48094
48108
  var _a, _b, _c;
48095
48109
  var originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
48096
48110
  var result;
@@ -48407,7 +48421,7 @@ var ts;
48407
48421
  }
48408
48422
  }
48409
48423
  if (!result) {
48410
- if (nameNotFoundMessage) {
48424
+ if (nameNotFoundMessage && produceDiagnostics) {
48411
48425
  if (!errorLocation ||
48412
48426
  !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
48413
48427
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -48417,7 +48431,7 @@ var ts;
48417
48431
  !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
48418
48432
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
48419
48433
  var suggestion = void 0;
48420
- if (suggestionCount < maximumSuggestionCount) {
48434
+ if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
48421
48435
  suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
48422
48436
  var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
48423
48437
  if (isGlobalScopeAugmentationDeclaration) {
@@ -48453,7 +48467,7 @@ var ts;
48453
48467
  return undefined;
48454
48468
  }
48455
48469
  // Perform extra checks only if error reporting was requested
48456
- if (nameNotFoundMessage) {
48470
+ if (nameNotFoundMessage && produceDiagnostics) {
48457
48471
  if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
48458
48472
  // We have a match, but the reference occurred within a property initializer and the identifier also binds
48459
48473
  // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
@@ -50929,7 +50943,7 @@ var ts;
50929
50943
  context.approximateLength += 6;
50930
50944
  return ts.factory.createKeywordTypeNode(147 /* ObjectKeyword */);
50931
50945
  }
50932
- if (isThisTypeParameter(type)) {
50946
+ if (ts.isThisTypeParameter(type)) {
50933
50947
  if (context.flags & 4194304 /* InObjectTypeLiteral */) {
50934
50948
  if (!context.encounteredError && !(context.flags & 32768 /* AllowThisInObjectLiteral */)) {
50935
50949
  context.encounteredError = true;
@@ -58874,7 +58888,7 @@ var ts;
58874
58888
  }
58875
58889
  function getGlobalSymbol(name, meaning, diagnostic) {
58876
58890
  // Don't track references for global symbols anyway, so value if `isReference` is arbitrary
58877
- return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false);
58891
+ return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ false);
58878
58892
  }
58879
58893
  function getGlobalType(name, arity, reportErrors) {
58880
58894
  var symbol = getGlobalTypeSymbol(name, reportErrors);
@@ -60453,9 +60467,6 @@ var ts;
60453
60467
  return (type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericMappedType(type) || isGenericTupleType(type) ? 8388608 /* IsGenericObjectType */ : 0) |
60454
60468
  (type.flags & (58982400 /* InstantiableNonPrimitive */ | 4194304 /* Index */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) && !isPatternLiteralType(type) ? 16777216 /* IsGenericIndexType */ : 0);
60455
60469
  }
60456
- function isThisTypeParameter(type) {
60457
- return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
60458
- }
60459
60470
  function getSimplifiedType(type, writing) {
60460
60471
  return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) :
60461
60472
  type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) :
@@ -65653,7 +65664,7 @@ var ts;
65653
65664
  // flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
65654
65665
  // no flags for all other types (including non-falsy literal types).
65655
65666
  function getFalsyFlags(type) {
65656
- return type.flags & 1048576 /* Union */ ? getFalsyFlagsOfTypes(type.types) :
65667
+ return type.flags & 3145728 /* UnionOrIntersection */ ? getFalsyFlagsOfTypes(type.types) :
65657
65668
  type.flags & 128 /* StringLiteral */ ? type.value === "" ? 128 /* StringLiteral */ : 0 :
65658
65669
  type.flags & 256 /* NumberLiteral */ ? type.value === 0 ? 256 /* NumberLiteral */ : 0 :
65659
65670
  type.flags & 2048 /* BigIntLiteral */ ? isZeroBigInt(type) ? 2048 /* BigIntLiteral */ : 0 :
@@ -67269,6 +67280,11 @@ var ts;
67269
67280
  case "BigInt64Array":
67270
67281
  case "BigUint64Array":
67271
67282
  return ts.Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_1_or_later;
67283
+ case "await":
67284
+ if (ts.isCallExpression(node.parent)) {
67285
+ return ts.Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function;
67286
+ }
67287
+ // falls through
67272
67288
  default:
67273
67289
  if (node.parent.kind === 295 /* ShorthandPropertyAssignment */) {
67274
67290
  return ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer;
@@ -68826,7 +68842,7 @@ var ts;
68826
68842
  function narrowByInKeyword(type, name, assumeTrue) {
68827
68843
  if (type.flags & 1048576 /* Union */
68828
68844
  || type.flags & 524288 /* Object */ && declaredType !== type
68829
- || isThisTypeParameter(type)
68845
+ || ts.isThisTypeParameter(type)
68830
68846
  || type.flags & 2097152 /* Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) {
68831
68847
  return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); });
68832
68848
  }
@@ -71646,15 +71662,9 @@ var ts;
71646
71662
  }
71647
71663
  }
71648
71664
  function isValidSpreadType(type) {
71649
- if (type.flags & 465829888 /* Instantiable */) {
71650
- var constraint = getBaseConstraintOfType(type);
71651
- if (constraint !== undefined) {
71652
- return isValidSpreadType(constraint);
71653
- }
71654
- }
71655
- return !!(type.flags & (1 /* Any */ | 67108864 /* NonPrimitive */ | 524288 /* Object */ | 58982400 /* InstantiableNonPrimitive */) ||
71656
- getFalsyFlags(type) & 117632 /* DefinitelyFalsy */ && isValidSpreadType(removeDefinitelyFalsyTypes(type)) ||
71657
- type.flags & 3145728 /* UnionOrIntersection */ && ts.every(type.types, isValidSpreadType));
71665
+ var t = removeDefinitelyFalsyTypes(mapType(type, getBaseConstraintOrType));
71666
+ return !!(t.flags & (1 /* Any */ | 67108864 /* NonPrimitive */ | 524288 /* Object */ | 58982400 /* InstantiableNonPrimitive */) ||
71667
+ t.flags & 3145728 /* UnionOrIntersection */ && ts.every(t.types, isValidSpreadType));
71658
71668
  }
71659
71669
  function checkJsxSelfClosingElementDeferred(node) {
71660
71670
  checkJsxOpeningLikeElementOrOpeningFragment(node);
@@ -72605,7 +72615,7 @@ var ts;
72605
72615
  }
72606
72616
  var propType;
72607
72617
  if (!prop) {
72608
- var indexInfo = !ts.isPrivateIdentifier(right) && (assignmentKind === 0 /* None */ || !isGenericObjectType(leftType) || isThisTypeParameter(leftType)) ?
72618
+ var indexInfo = !ts.isPrivateIdentifier(right) && (assignmentKind === 0 /* None */ || !isGenericObjectType(leftType) || ts.isThisTypeParameter(leftType)) ?
72609
72619
  getApplicableIndexInfoForName(apparentType, right.escapedText) : undefined;
72610
72620
  if (!(indexInfo && indexInfo.type)) {
72611
72621
  var isUncheckedJS = isUncheckedJSSuggestion(node, leftType.symbol, /*excludeClasses*/ true);
@@ -72622,7 +72632,7 @@ var ts;
72622
72632
  return anyType;
72623
72633
  }
72624
72634
  if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) {
72625
- reportNonexistentProperty(right, isThisTypeParameter(leftType) ? apparentType : leftType, isUncheckedJS);
72635
+ reportNonexistentProperty(right, ts.isThisTypeParameter(leftType) ? apparentType : leftType, isUncheckedJS);
72626
72636
  }
72627
72637
  return errorType;
72628
72638
  }
@@ -72915,7 +72925,7 @@ var ts;
72915
72925
  }
72916
72926
  function getSuggestedSymbolForNonexistentSymbol(location, outerName, meaning) {
72917
72927
  ts.Debug.assert(outerName !== undefined, "outername should always be defined");
72918
- var result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, function (symbols, name, meaning) {
72928
+ var result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ true, function (symbols, name, meaning) {
72919
72929
  ts.Debug.assertEqual(outerName, name, "name should equal outerName");
72920
72930
  var symbol = getSymbol(symbols, name, meaning);
72921
72931
  // Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
@@ -73161,7 +73171,7 @@ var ts;
73161
73171
  }
73162
73172
  var effectiveIndexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : indexType;
73163
73173
  var accessFlags = ts.isAssignmentTarget(node) ?
73164
- 4 /* Writing */ | (isGenericObjectType(objectType) && !isThisTypeParameter(objectType) ? 2 /* NoIndexSignatures */ : 0) :
73174
+ 4 /* Writing */ | (isGenericObjectType(objectType) && !ts.isThisTypeParameter(objectType) ? 2 /* NoIndexSignatures */ : 0) :
73165
73175
  32 /* ExpressionPosition */;
73166
73176
  var indexedAccessType = getIndexedAccessTypeOrUndefined(objectType, effectiveIndexType, accessFlags, node) || errorType;
73167
73177
  return checkIndexedAccessIndexType(getFlowTypeOfAccessExpression(node, getNodeLinks(node).resolvedSymbol, indexedAccessType, indexExpression, checkMode), node);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "typescript",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "4.6.0-dev.20211203",
5
+ "version": "4.6.0-dev.20211204",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [