typescript 4.8.0-dev.20220615 → 4.8.0-dev.20220616

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.
package/lib/tsc.js CHANGED
@@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  var ts;
70
70
  (function (ts) {
71
71
  ts.versionMajorMinor = "4.8";
72
- ts.version = ts.versionMajorMinor + ".0-dev.20220615";
72
+ ts.version = ts.versionMajorMinor + ".0-dev.20220616";
73
73
  var NativeCollections;
74
74
  (function (NativeCollections) {
75
75
  var globals = typeof globalThis !== "undefined" ? globalThis :
@@ -5642,9 +5642,11 @@ var ts;
5642
5642
  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}'.", undefined, true),
5643
5643
  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."),
5644
5644
  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."),
5645
- 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."),
5645
+ This_type_parameter_might_need_an_extends_0_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_might_need_an_extends_0_constraint_2208", "This type parameter might need an `extends {0}` constraint."),
5646
5646
  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."),
5647
5647
  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."),
5648
+ Add_extends_constraint: diag(2211, ts.DiagnosticCategory.Message, "Add_extends_constraint_2211", "Add `extends` constraint."),
5649
+ Add_extends_constraint_to_all_type_parameters: diag(2212, ts.DiagnosticCategory.Message, "Add_extends_constraint_to_all_type_parameters_2212", "Add `extends` constraint to all type parameters"),
5648
5650
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
5649
5651
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
5650
5652
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -28778,9 +28780,10 @@ var ts;
28778
28780
  }
28779
28781
  nextToken();
28780
28782
  var typeArguments = parseDelimitedList(20, parseType);
28781
- if (!parseExpected(31)) {
28783
+ if (reScanGreaterToken() !== 31) {
28782
28784
  return undefined;
28783
28785
  }
28786
+ nextToken();
28784
28787
  return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments : undefined;
28785
28788
  }
28786
28789
  function canFollowTypeArgumentsInExpression() {
@@ -43220,6 +43223,9 @@ var ts;
43220
43223
  if (symbol && symbol.flags & 262144 && meaning & 788968) {
43221
43224
  return { accessibility: 0 };
43222
43225
  }
43226
+ if (!symbol && ts.isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(ts.getThisContainer(firstIdentifier, false)), firstIdentifier, meaning, false).accessibility === 0) {
43227
+ return { accessibility: 0 };
43228
+ }
43223
43229
  return (symbol && hasVisibleDeclarations(symbol, true)) || {
43224
43230
  accessibility: 1,
43225
43231
  errorSymbolName: ts.getTextOfNode(firstIdentifier),
@@ -54610,8 +54616,13 @@ var ts;
54610
54616
  return;
54611
54617
  }
54612
54618
  reportRelationError(headMessage, source, target);
54613
- if (strictNullChecks && source.flags & 8650752 && ((_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))) {
54614
- associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
54619
+ if (source.flags & 262144 && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source)) {
54620
+ var syntheticParam = cloneTypeParameter(source);
54621
+ syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
54622
+ if (hasNonCircularBaseConstraint(syntheticParam)) {
54623
+ var targetConstraintString = typeToString(target, source.symbol.declarations[0]);
54624
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
54625
+ }
54615
54626
  }
54616
54627
  }
54617
54628
  function traceUnionsOrIntersectionsTooLarge(source, target) {
package/lib/tsserver.js CHANGED
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220615";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220616";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -8483,9 +8483,11 @@ var ts;
8483
8483
  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),
8484
8484
  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."),
8485
8485
  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."),
8486
- 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."),
8486
+ This_type_parameter_might_need_an_extends_0_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_might_need_an_extends_0_constraint_2208", "This type parameter might need an `extends {0}` constraint."),
8487
8487
  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."),
8488
8488
  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."),
8489
+ Add_extends_constraint: diag(2211, ts.DiagnosticCategory.Message, "Add_extends_constraint_2211", "Add `extends` constraint."),
8490
+ Add_extends_constraint_to_all_type_parameters: diag(2212, ts.DiagnosticCategory.Message, "Add_extends_constraint_to_all_type_parameters_2212", "Add `extends` constraint to all type parameters"),
8489
8491
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
8490
8492
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
8491
8493
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -35787,10 +35789,11 @@ var ts;
35787
35789
  }
35788
35790
  nextToken();
35789
35791
  var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
35790
- if (!parseExpected(31 /* GreaterThanToken */)) {
35792
+ if (reScanGreaterToken() !== 31 /* GreaterThanToken */) {
35791
35793
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35792
35794
  return undefined;
35793
35795
  }
35796
+ nextToken();
35794
35797
  // We successfully parsed a type argument list. The next token determines whether we want to
35795
35798
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35796
35799
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -52540,6 +52543,9 @@ var ts;
52540
52543
  if (symbol && symbol.flags & 262144 /* TypeParameter */ && meaning & 788968 /* Type */) {
52541
52544
  return { accessibility: 0 /* Accessible */ };
52542
52545
  }
52546
+ if (!symbol && ts.isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(ts.getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === 0 /* Accessible */) {
52547
+ return { accessibility: 0 /* Accessible */ };
52548
+ }
52543
52549
  // Verify if the symbol is accessible
52544
52550
  return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {
52545
52551
  accessibility: 1 /* NotAccessible */,
@@ -65500,8 +65506,13 @@ var ts;
65500
65506
  return;
65501
65507
  }
65502
65508
  reportRelationError(headMessage, source, target);
65503
- 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 */))) {
65504
- associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
65509
+ if (source.flags & 262144 /* TypeParameter */ && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source)) {
65510
+ var syntheticParam = cloneTypeParameter(source);
65511
+ syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
65512
+ if (hasNonCircularBaseConstraint(syntheticParam)) {
65513
+ var targetConstraintString = typeToString(target, source.symbol.declarations[0]);
65514
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
65515
+ }
65505
65516
  }
65506
65517
  }
65507
65518
  function traceUnionsOrIntersectionsTooLarge(source, target) {
@@ -145216,7 +145227,7 @@ var ts;
145216
145227
  return type.symbol && (type.symbol.flags & 1536 /* Module */);
145217
145228
  }
145218
145229
  function visitVariableLikeDeclaration(decl) {
145219
- if (!decl.initializer || ts.isBindingPattern(decl.name)) {
145230
+ if (!decl.initializer || ts.isBindingPattern(decl.name) || ts.isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
145220
145231
  return;
145221
145232
  }
145222
145233
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(decl);
@@ -145344,6 +145355,9 @@ var ts;
145344
145355
  }
145345
145356
  for (var i = 0; i < node.parameters.length && i < signature.parameters.length; ++i) {
145346
145357
  var param = node.parameters[i];
145358
+ if (!isHintableDeclaration(param)) {
145359
+ continue;
145360
+ }
145347
145361
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(param);
145348
145362
  if (effectiveTypeAnnotation) {
145349
145363
  continue;
@@ -145385,6 +145399,13 @@ var ts;
145385
145399
  function isUndefined(name) {
145386
145400
  return name === "undefined";
145387
145401
  }
145402
+ function isHintableDeclaration(node) {
145403
+ if ((ts.isParameterDeclaration(node) || ts.isVariableDeclaration(node) && ts.isVarConst(node)) && node.initializer) {
145404
+ var initializer = ts.skipParentheses(node.initializer);
145405
+ return !(isHintableLiteral(initializer) || ts.isNewExpression(initializer) || ts.isObjectLiteralExpression(initializer) || ts.isAssertionExpression(initializer));
145406
+ }
145407
+ return true;
145408
+ }
145388
145409
  }
145389
145410
  InlayHints.provideInlayHints = provideInlayHints;
145390
145411
  })(InlayHints = ts.InlayHints || (ts.InlayHints = {}));
@@ -154823,6 +154844,77 @@ var ts;
154823
154844
  })(ts || (ts = {}));
154824
154845
  /* @internal */
154825
154846
  var ts;
154847
+ (function (ts) {
154848
+ var codefix;
154849
+ (function (codefix) {
154850
+ var fixId = "addMissingConstraint";
154851
+ var errorCodes = [
154852
+ // We want errors this could be attached to:
154853
+ // Diagnostics.This_type_parameter_probably_needs_an_extends_0_constraint
154854
+ ts.Diagnostics.Type_0_is_not_comparable_to_type_1.code,
154855
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated.code,
154856
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
154857
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1.code,
154858
+ ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
154859
+ ts.Diagnostics.Property_0_is_incompatible_with_index_signature.code,
154860
+ ts.Diagnostics.Property_0_in_type_1_is_not_assignable_to_type_2.code,
154861
+ ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1.code,
154862
+ ];
154863
+ codefix.registerCodeFix({
154864
+ errorCodes: errorCodes,
154865
+ getCodeActions: function (context) {
154866
+ var sourceFile = context.sourceFile, span = context.span, program = context.program;
154867
+ var related = getDiagnosticRelatedInfo(program, sourceFile, span);
154868
+ if (!related) {
154869
+ return;
154870
+ }
154871
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
154872
+ return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
154873
+ },
154874
+ fixIds: [fixId],
154875
+ getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
154876
+ var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
154877
+ if (!info)
154878
+ return;
154879
+ return addMissingConstraint(changes, info);
154880
+ }); },
154881
+ });
154882
+ function getDiagnosticRelatedInfo(program, sourceFile, span) {
154883
+ var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
154884
+ if (!diag || !diag.relatedInformation)
154885
+ return;
154886
+ var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
154887
+ if (!related)
154888
+ return;
154889
+ return related;
154890
+ }
154891
+ function addMissingConstraint(changes, related) {
154892
+ var decl = findAncestorMatchingSpan(related.file, related);
154893
+ if (!decl)
154894
+ return;
154895
+ if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
154896
+ decl = decl.parent;
154897
+ }
154898
+ if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
154899
+ return; // should only issue fix on type parameters written using `extends`
154900
+ var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
154901
+ if (!newConstraint)
154902
+ return;
154903
+ var newConstraintText = newConstraint[1];
154904
+ changes.insertText(related.file, related.start + related.length, " extends " + newConstraintText);
154905
+ }
154906
+ function findAncestorMatchingSpan(sourceFile, span) {
154907
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
154908
+ var end = ts.textSpanEnd(span);
154909
+ while (token.end < end) {
154910
+ token = token.parent;
154911
+ }
154912
+ return token;
154913
+ }
154914
+ })(codefix = ts.codefix || (ts.codefix = {}));
154915
+ })(ts || (ts = {}));
154916
+ /* @internal */
154917
+ var ts;
154826
154918
  (function (ts) {
154827
154919
  var codefix;
154828
154920
  (function (codefix) {
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220615";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220616";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -8677,9 +8677,11 @@ var ts;
8677
8677
  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),
8678
8678
  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."),
8679
8679
  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."),
8680
- 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."),
8680
+ This_type_parameter_might_need_an_extends_0_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_might_need_an_extends_0_constraint_2208", "This type parameter might need an `extends {0}` constraint."),
8681
8681
  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."),
8682
8682
  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."),
8683
+ Add_extends_constraint: diag(2211, ts.DiagnosticCategory.Message, "Add_extends_constraint_2211", "Add `extends` constraint."),
8684
+ Add_extends_constraint_to_all_type_parameters: diag(2212, ts.DiagnosticCategory.Message, "Add_extends_constraint_to_all_type_parameters_2212", "Add `extends` constraint to all type parameters"),
8683
8685
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
8684
8686
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
8685
8687
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -35981,10 +35983,11 @@ var ts;
35981
35983
  }
35982
35984
  nextToken();
35983
35985
  var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
35984
- if (!parseExpected(31 /* GreaterThanToken */)) {
35986
+ if (reScanGreaterToken() !== 31 /* GreaterThanToken */) {
35985
35987
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35986
35988
  return undefined;
35987
35989
  }
35990
+ nextToken();
35988
35991
  // We successfully parsed a type argument list. The next token determines whether we want to
35989
35992
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35990
35993
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -52734,6 +52737,9 @@ var ts;
52734
52737
  if (symbol && symbol.flags & 262144 /* TypeParameter */ && meaning & 788968 /* Type */) {
52735
52738
  return { accessibility: 0 /* Accessible */ };
52736
52739
  }
52740
+ if (!symbol && ts.isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(ts.getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === 0 /* Accessible */) {
52741
+ return { accessibility: 0 /* Accessible */ };
52742
+ }
52737
52743
  // Verify if the symbol is accessible
52738
52744
  return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {
52739
52745
  accessibility: 1 /* NotAccessible */,
@@ -65694,8 +65700,13 @@ var ts;
65694
65700
  return;
65695
65701
  }
65696
65702
  reportRelationError(headMessage, source, target);
65697
- 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 */))) {
65698
- associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
65703
+ if (source.flags & 262144 /* TypeParameter */ && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source)) {
65704
+ var syntheticParam = cloneTypeParameter(source);
65705
+ syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
65706
+ if (hasNonCircularBaseConstraint(syntheticParam)) {
65707
+ var targetConstraintString = typeToString(target, source.symbol.declarations[0]);
65708
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
65709
+ }
65699
65710
  }
65700
65711
  }
65701
65712
  function traceUnionsOrIntersectionsTooLarge(source, target) {
@@ -145829,7 +145840,7 @@ var ts;
145829
145840
  return type.symbol && (type.symbol.flags & 1536 /* Module */);
145830
145841
  }
145831
145842
  function visitVariableLikeDeclaration(decl) {
145832
- if (!decl.initializer || ts.isBindingPattern(decl.name)) {
145843
+ if (!decl.initializer || ts.isBindingPattern(decl.name) || ts.isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
145833
145844
  return;
145834
145845
  }
145835
145846
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(decl);
@@ -145957,6 +145968,9 @@ var ts;
145957
145968
  }
145958
145969
  for (var i = 0; i < node.parameters.length && i < signature.parameters.length; ++i) {
145959
145970
  var param = node.parameters[i];
145971
+ if (!isHintableDeclaration(param)) {
145972
+ continue;
145973
+ }
145960
145974
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(param);
145961
145975
  if (effectiveTypeAnnotation) {
145962
145976
  continue;
@@ -145998,6 +146012,13 @@ var ts;
145998
146012
  function isUndefined(name) {
145999
146013
  return name === "undefined";
146000
146014
  }
146015
+ function isHintableDeclaration(node) {
146016
+ if ((ts.isParameterDeclaration(node) || ts.isVariableDeclaration(node) && ts.isVarConst(node)) && node.initializer) {
146017
+ var initializer = ts.skipParentheses(node.initializer);
146018
+ return !(isHintableLiteral(initializer) || ts.isNewExpression(initializer) || ts.isObjectLiteralExpression(initializer) || ts.isAssertionExpression(initializer));
146019
+ }
146020
+ return true;
146021
+ }
146001
146022
  }
146002
146023
  InlayHints.provideInlayHints = provideInlayHints;
146003
146024
  })(InlayHints = ts.InlayHints || (ts.InlayHints = {}));
@@ -155436,6 +155457,77 @@ var ts;
155436
155457
  })(ts || (ts = {}));
155437
155458
  /* @internal */
155438
155459
  var ts;
155460
+ (function (ts) {
155461
+ var codefix;
155462
+ (function (codefix) {
155463
+ var fixId = "addMissingConstraint";
155464
+ var errorCodes = [
155465
+ // We want errors this could be attached to:
155466
+ // Diagnostics.This_type_parameter_probably_needs_an_extends_0_constraint
155467
+ ts.Diagnostics.Type_0_is_not_comparable_to_type_1.code,
155468
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated.code,
155469
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
155470
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1.code,
155471
+ ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
155472
+ ts.Diagnostics.Property_0_is_incompatible_with_index_signature.code,
155473
+ ts.Diagnostics.Property_0_in_type_1_is_not_assignable_to_type_2.code,
155474
+ ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1.code,
155475
+ ];
155476
+ codefix.registerCodeFix({
155477
+ errorCodes: errorCodes,
155478
+ getCodeActions: function (context) {
155479
+ var sourceFile = context.sourceFile, span = context.span, program = context.program;
155480
+ var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155481
+ if (!related) {
155482
+ return;
155483
+ }
155484
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155485
+ return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155486
+ },
155487
+ fixIds: [fixId],
155488
+ getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155489
+ var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155490
+ if (!info)
155491
+ return;
155492
+ return addMissingConstraint(changes, info);
155493
+ }); },
155494
+ });
155495
+ function getDiagnosticRelatedInfo(program, sourceFile, span) {
155496
+ var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155497
+ if (!diag || !diag.relatedInformation)
155498
+ return;
155499
+ var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
155500
+ if (!related)
155501
+ return;
155502
+ return related;
155503
+ }
155504
+ function addMissingConstraint(changes, related) {
155505
+ var decl = findAncestorMatchingSpan(related.file, related);
155506
+ if (!decl)
155507
+ return;
155508
+ if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
155509
+ decl = decl.parent;
155510
+ }
155511
+ if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
155512
+ return; // should only issue fix on type parameters written using `extends`
155513
+ var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
155514
+ if (!newConstraint)
155515
+ return;
155516
+ var newConstraintText = newConstraint[1];
155517
+ changes.insertText(related.file, related.start + related.length, " extends " + newConstraintText);
155518
+ }
155519
+ function findAncestorMatchingSpan(sourceFile, span) {
155520
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
155521
+ var end = ts.textSpanEnd(span);
155522
+ while (token.end < end) {
155523
+ token = token.parent;
155524
+ }
155525
+ return token;
155526
+ }
155527
+ })(codefix = ts.codefix || (ts.codefix = {}));
155528
+ })(ts || (ts = {}));
155529
+ /* @internal */
155530
+ var ts;
155439
155531
  (function (ts) {
155440
155532
  var codefix;
155441
155533
  (function (codefix) {
package/lib/typescript.js CHANGED
@@ -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.20220615";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220616";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -8668,9 +8668,11 @@ var ts;
8668
8668
  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),
8669
8669
  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."),
8670
8670
  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."),
8671
- 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."),
8671
+ This_type_parameter_might_need_an_extends_0_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_might_need_an_extends_0_constraint_2208", "This type parameter might need an `extends {0}` constraint."),
8672
8672
  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."),
8673
8673
  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."),
8674
+ Add_extends_constraint: diag(2211, ts.DiagnosticCategory.Message, "Add_extends_constraint_2211", "Add `extends` constraint."),
8675
+ Add_extends_constraint_to_all_type_parameters: diag(2212, ts.DiagnosticCategory.Message, "Add_extends_constraint_to_all_type_parameters_2212", "Add `extends` constraint to all type parameters"),
8674
8676
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
8675
8677
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
8676
8678
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -35972,10 +35974,11 @@ var ts;
35972
35974
  }
35973
35975
  nextToken();
35974
35976
  var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
35975
- if (!parseExpected(31 /* GreaterThanToken */)) {
35977
+ if (reScanGreaterToken() !== 31 /* GreaterThanToken */) {
35976
35978
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35977
35979
  return undefined;
35978
35980
  }
35981
+ nextToken();
35979
35982
  // We successfully parsed a type argument list. The next token determines whether we want to
35980
35983
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35981
35984
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -52725,6 +52728,9 @@ var ts;
52725
52728
  if (symbol && symbol.flags & 262144 /* TypeParameter */ && meaning & 788968 /* Type */) {
52726
52729
  return { accessibility: 0 /* Accessible */ };
52727
52730
  }
52731
+ if (!symbol && ts.isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(ts.getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === 0 /* Accessible */) {
52732
+ return { accessibility: 0 /* Accessible */ };
52733
+ }
52728
52734
  // Verify if the symbol is accessible
52729
52735
  return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {
52730
52736
  accessibility: 1 /* NotAccessible */,
@@ -65685,8 +65691,13 @@ var ts;
65685
65691
  return;
65686
65692
  }
65687
65693
  reportRelationError(headMessage, source, target);
65688
- 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 */))) {
65689
- associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
65694
+ if (source.flags & 262144 /* TypeParameter */ && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source)) {
65695
+ var syntheticParam = cloneTypeParameter(source);
65696
+ syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
65697
+ if (hasNonCircularBaseConstraint(syntheticParam)) {
65698
+ var targetConstraintString = typeToString(target, source.symbol.declarations[0]);
65699
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
65700
+ }
65690
65701
  }
65691
65702
  }
65692
65703
  function traceUnionsOrIntersectionsTooLarge(source, target) {
@@ -145820,7 +145831,7 @@ var ts;
145820
145831
  return type.symbol && (type.symbol.flags & 1536 /* Module */);
145821
145832
  }
145822
145833
  function visitVariableLikeDeclaration(decl) {
145823
- if (!decl.initializer || ts.isBindingPattern(decl.name)) {
145834
+ if (!decl.initializer || ts.isBindingPattern(decl.name) || ts.isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
145824
145835
  return;
145825
145836
  }
145826
145837
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(decl);
@@ -145948,6 +145959,9 @@ var ts;
145948
145959
  }
145949
145960
  for (var i = 0; i < node.parameters.length && i < signature.parameters.length; ++i) {
145950
145961
  var param = node.parameters[i];
145962
+ if (!isHintableDeclaration(param)) {
145963
+ continue;
145964
+ }
145951
145965
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(param);
145952
145966
  if (effectiveTypeAnnotation) {
145953
145967
  continue;
@@ -145989,6 +146003,13 @@ var ts;
145989
146003
  function isUndefined(name) {
145990
146004
  return name === "undefined";
145991
146005
  }
146006
+ function isHintableDeclaration(node) {
146007
+ if ((ts.isParameterDeclaration(node) || ts.isVariableDeclaration(node) && ts.isVarConst(node)) && node.initializer) {
146008
+ var initializer = ts.skipParentheses(node.initializer);
146009
+ return !(isHintableLiteral(initializer) || ts.isNewExpression(initializer) || ts.isObjectLiteralExpression(initializer) || ts.isAssertionExpression(initializer));
146010
+ }
146011
+ return true;
146012
+ }
145992
146013
  }
145993
146014
  InlayHints.provideInlayHints = provideInlayHints;
145994
146015
  })(InlayHints = ts.InlayHints || (ts.InlayHints = {}));
@@ -155427,6 +155448,77 @@ var ts;
155427
155448
  })(ts || (ts = {}));
155428
155449
  /* @internal */
155429
155450
  var ts;
155451
+ (function (ts) {
155452
+ var codefix;
155453
+ (function (codefix) {
155454
+ var fixId = "addMissingConstraint";
155455
+ var errorCodes = [
155456
+ // We want errors this could be attached to:
155457
+ // Diagnostics.This_type_parameter_probably_needs_an_extends_0_constraint
155458
+ ts.Diagnostics.Type_0_is_not_comparable_to_type_1.code,
155459
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated.code,
155460
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
155461
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1.code,
155462
+ ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
155463
+ ts.Diagnostics.Property_0_is_incompatible_with_index_signature.code,
155464
+ ts.Diagnostics.Property_0_in_type_1_is_not_assignable_to_type_2.code,
155465
+ ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1.code,
155466
+ ];
155467
+ codefix.registerCodeFix({
155468
+ errorCodes: errorCodes,
155469
+ getCodeActions: function (context) {
155470
+ var sourceFile = context.sourceFile, span = context.span, program = context.program;
155471
+ var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155472
+ if (!related) {
155473
+ return;
155474
+ }
155475
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155476
+ return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155477
+ },
155478
+ fixIds: [fixId],
155479
+ getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155480
+ var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155481
+ if (!info)
155482
+ return;
155483
+ return addMissingConstraint(changes, info);
155484
+ }); },
155485
+ });
155486
+ function getDiagnosticRelatedInfo(program, sourceFile, span) {
155487
+ var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155488
+ if (!diag || !diag.relatedInformation)
155489
+ return;
155490
+ var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
155491
+ if (!related)
155492
+ return;
155493
+ return related;
155494
+ }
155495
+ function addMissingConstraint(changes, related) {
155496
+ var decl = findAncestorMatchingSpan(related.file, related);
155497
+ if (!decl)
155498
+ return;
155499
+ if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
155500
+ decl = decl.parent;
155501
+ }
155502
+ if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
155503
+ return; // should only issue fix on type parameters written using `extends`
155504
+ var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
155505
+ if (!newConstraint)
155506
+ return;
155507
+ var newConstraintText = newConstraint[1];
155508
+ changes.insertText(related.file, related.start + related.length, " extends " + newConstraintText);
155509
+ }
155510
+ function findAncestorMatchingSpan(sourceFile, span) {
155511
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
155512
+ var end = ts.textSpanEnd(span);
155513
+ while (token.end < end) {
155514
+ token = token.parent;
155515
+ }
155516
+ return token;
155517
+ }
155518
+ })(codefix = ts.codefix || (ts.codefix = {}));
155519
+ })(ts || (ts = {}));
155520
+ /* @internal */
155521
+ var ts;
155430
155522
  (function (ts) {
155431
155523
  var codefix;
155432
155524
  (function (codefix) {
@@ -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.20220615";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220616";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -8668,9 +8668,11 @@ var ts;
8668
8668
  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),
8669
8669
  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."),
8670
8670
  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."),
8671
- 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."),
8671
+ This_type_parameter_might_need_an_extends_0_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_might_need_an_extends_0_constraint_2208", "This type parameter might need an `extends {0}` constraint."),
8672
8672
  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."),
8673
8673
  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."),
8674
+ Add_extends_constraint: diag(2211, ts.DiagnosticCategory.Message, "Add_extends_constraint_2211", "Add `extends` constraint."),
8675
+ Add_extends_constraint_to_all_type_parameters: diag(2212, ts.DiagnosticCategory.Message, "Add_extends_constraint_to_all_type_parameters_2212", "Add `extends` constraint to all type parameters"),
8674
8676
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
8675
8677
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
8676
8678
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -35972,10 +35974,11 @@ var ts;
35972
35974
  }
35973
35975
  nextToken();
35974
35976
  var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
35975
- if (!parseExpected(31 /* GreaterThanToken */)) {
35977
+ if (reScanGreaterToken() !== 31 /* GreaterThanToken */) {
35976
35978
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35977
35979
  return undefined;
35978
35980
  }
35981
+ nextToken();
35979
35982
  // We successfully parsed a type argument list. The next token determines whether we want to
35980
35983
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35981
35984
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -52725,6 +52728,9 @@ var ts;
52725
52728
  if (symbol && symbol.flags & 262144 /* TypeParameter */ && meaning & 788968 /* Type */) {
52726
52729
  return { accessibility: 0 /* Accessible */ };
52727
52730
  }
52731
+ if (!symbol && ts.isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(ts.getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === 0 /* Accessible */) {
52732
+ return { accessibility: 0 /* Accessible */ };
52733
+ }
52728
52734
  // Verify if the symbol is accessible
52729
52735
  return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {
52730
52736
  accessibility: 1 /* NotAccessible */,
@@ -65685,8 +65691,13 @@ var ts;
65685
65691
  return;
65686
65692
  }
65687
65693
  reportRelationError(headMessage, source, target);
65688
- 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 */))) {
65689
- associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
65694
+ if (source.flags & 262144 /* TypeParameter */ && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source)) {
65695
+ var syntheticParam = cloneTypeParameter(source);
65696
+ syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
65697
+ if (hasNonCircularBaseConstraint(syntheticParam)) {
65698
+ var targetConstraintString = typeToString(target, source.symbol.declarations[0]);
65699
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
65700
+ }
65690
65701
  }
65691
65702
  }
65692
65703
  function traceUnionsOrIntersectionsTooLarge(source, target) {
@@ -145820,7 +145831,7 @@ var ts;
145820
145831
  return type.symbol && (type.symbol.flags & 1536 /* Module */);
145821
145832
  }
145822
145833
  function visitVariableLikeDeclaration(decl) {
145823
- if (!decl.initializer || ts.isBindingPattern(decl.name)) {
145834
+ if (!decl.initializer || ts.isBindingPattern(decl.name) || ts.isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
145824
145835
  return;
145825
145836
  }
145826
145837
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(decl);
@@ -145948,6 +145959,9 @@ var ts;
145948
145959
  }
145949
145960
  for (var i = 0; i < node.parameters.length && i < signature.parameters.length; ++i) {
145950
145961
  var param = node.parameters[i];
145962
+ if (!isHintableDeclaration(param)) {
145963
+ continue;
145964
+ }
145951
145965
  var effectiveTypeAnnotation = ts.getEffectiveTypeAnnotationNode(param);
145952
145966
  if (effectiveTypeAnnotation) {
145953
145967
  continue;
@@ -145989,6 +146003,13 @@ var ts;
145989
146003
  function isUndefined(name) {
145990
146004
  return name === "undefined";
145991
146005
  }
146006
+ function isHintableDeclaration(node) {
146007
+ if ((ts.isParameterDeclaration(node) || ts.isVariableDeclaration(node) && ts.isVarConst(node)) && node.initializer) {
146008
+ var initializer = ts.skipParentheses(node.initializer);
146009
+ return !(isHintableLiteral(initializer) || ts.isNewExpression(initializer) || ts.isObjectLiteralExpression(initializer) || ts.isAssertionExpression(initializer));
146010
+ }
146011
+ return true;
146012
+ }
145992
146013
  }
145993
146014
  InlayHints.provideInlayHints = provideInlayHints;
145994
146015
  })(InlayHints = ts.InlayHints || (ts.InlayHints = {}));
@@ -155427,6 +155448,77 @@ var ts;
155427
155448
  })(ts || (ts = {}));
155428
155449
  /* @internal */
155429
155450
  var ts;
155451
+ (function (ts) {
155452
+ var codefix;
155453
+ (function (codefix) {
155454
+ var fixId = "addMissingConstraint";
155455
+ var errorCodes = [
155456
+ // We want errors this could be attached to:
155457
+ // Diagnostics.This_type_parameter_probably_needs_an_extends_0_constraint
155458
+ ts.Diagnostics.Type_0_is_not_comparable_to_type_1.code,
155459
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated.code,
155460
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
155461
+ ts.Diagnostics.Type_0_is_not_assignable_to_type_1.code,
155462
+ ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties.code,
155463
+ ts.Diagnostics.Property_0_is_incompatible_with_index_signature.code,
155464
+ ts.Diagnostics.Property_0_in_type_1_is_not_assignable_to_type_2.code,
155465
+ ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1.code,
155466
+ ];
155467
+ codefix.registerCodeFix({
155468
+ errorCodes: errorCodes,
155469
+ getCodeActions: function (context) {
155470
+ var sourceFile = context.sourceFile, span = context.span, program = context.program;
155471
+ var related = getDiagnosticRelatedInfo(program, sourceFile, span);
155472
+ if (!related) {
155473
+ return;
155474
+ }
155475
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingConstraint(t, related); });
155476
+ return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_extends_constraint, fixId, ts.Diagnostics.Add_extends_constraint_to_all_type_parameters)];
155477
+ },
155478
+ fixIds: [fixId],
155479
+ getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
155480
+ var info = getDiagnosticRelatedInfo(context.program, context.sourceFile, diag);
155481
+ if (!info)
155482
+ return;
155483
+ return addMissingConstraint(changes, info);
155484
+ }); },
155485
+ });
155486
+ function getDiagnosticRelatedInfo(program, sourceFile, span) {
155487
+ var diag = ts.find(program.getSemanticDiagnostics(sourceFile), function (diag) { return diag.start === span.start && diag.length === span.length; });
155488
+ if (!diag || !diag.relatedInformation)
155489
+ return;
155490
+ var related = ts.find(diag.relatedInformation, function (related) { return related.code === ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint.code; });
155491
+ if (!related)
155492
+ return;
155493
+ return related;
155494
+ }
155495
+ function addMissingConstraint(changes, related) {
155496
+ var decl = findAncestorMatchingSpan(related.file, related);
155497
+ if (!decl)
155498
+ return;
155499
+ if (ts.isIdentifier(decl) && ts.isTypeParameterDeclaration(decl.parent)) {
155500
+ decl = decl.parent;
155501
+ }
155502
+ if (!ts.isTypeParameterDeclaration(decl) || ts.isMappedTypeNode(decl.parent))
155503
+ return; // should only issue fix on type parameters written using `extends`
155504
+ var newConstraint = ts.flattenDiagnosticMessageText(related.messageText, "\n", 0).match(/`extends (.*)`/);
155505
+ if (!newConstraint)
155506
+ return;
155507
+ var newConstraintText = newConstraint[1];
155508
+ changes.insertText(related.file, related.start + related.length, " extends " + newConstraintText);
155509
+ }
155510
+ function findAncestorMatchingSpan(sourceFile, span) {
155511
+ var token = ts.getTokenAtPosition(sourceFile, span.start);
155512
+ var end = ts.textSpanEnd(span);
155513
+ while (token.end < end) {
155514
+ token = token.parent;
155515
+ }
155516
+ return token;
155517
+ }
155518
+ })(codefix = ts.codefix || (ts.codefix = {}));
155519
+ })(ts || (ts = {}));
155520
+ /* @internal */
155521
+ var ts;
155430
155522
  (function (ts) {
155431
155523
  var codefix;
155432
155524
  (function (codefix) {
@@ -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.20220615";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220616";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -8463,9 +8463,11 @@ var ts;
8463
8463
  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),
8464
8464
  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."),
8465
8465
  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."),
8466
- 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."),
8466
+ This_type_parameter_might_need_an_extends_0_constraint: diag(2208, ts.DiagnosticCategory.Error, "This_type_parameter_might_need_an_extends_0_constraint_2208", "This type parameter might need an `extends {0}` constraint."),
8467
8467
  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."),
8468
8468
  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."),
8469
+ Add_extends_constraint: diag(2211, ts.DiagnosticCategory.Message, "Add_extends_constraint_2211", "Add `extends` constraint."),
8470
+ Add_extends_constraint_to_all_type_parameters: diag(2212, ts.DiagnosticCategory.Message, "Add_extends_constraint_to_all_type_parameters_2212", "Add `extends` constraint to all type parameters"),
8469
8471
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
8470
8472
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
8471
8473
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -35767,10 +35769,11 @@ var ts;
35767
35769
  }
35768
35770
  nextToken();
35769
35771
  var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
35770
- if (!parseExpected(31 /* GreaterThanToken */)) {
35772
+ if (reScanGreaterToken() !== 31 /* GreaterThanToken */) {
35771
35773
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
35772
35774
  return undefined;
35773
35775
  }
35776
+ nextToken();
35774
35777
  // We successfully parsed a type argument list. The next token determines whether we want to
35775
35778
  // treat it as such. If the type argument list is followed by `(` or a template literal, as in
35776
35779
  // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
@@ -52520,6 +52523,9 @@ var ts;
52520
52523
  if (symbol && symbol.flags & 262144 /* TypeParameter */ && meaning & 788968 /* Type */) {
52521
52524
  return { accessibility: 0 /* Accessible */ };
52522
52525
  }
52526
+ if (!symbol && ts.isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(ts.getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === 0 /* Accessible */) {
52527
+ return { accessibility: 0 /* Accessible */ };
52528
+ }
52523
52529
  // Verify if the symbol is accessible
52524
52530
  return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {
52525
52531
  accessibility: 1 /* NotAccessible */,
@@ -65480,8 +65486,13 @@ var ts;
65480
65486
  return;
65481
65487
  }
65482
65488
  reportRelationError(headMessage, source, target);
65483
- 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 */))) {
65484
- associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_probably_needs_an_extends_object_constraint));
65489
+ if (source.flags & 262144 /* TypeParameter */ && ((_b = (_a = source.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0]) && !getConstraintOfType(source)) {
65490
+ var syntheticParam = cloneTypeParameter(source);
65491
+ syntheticParam.constraint = instantiateType(target, makeUnaryTypeMapper(source, syntheticParam));
65492
+ if (hasNonCircularBaseConstraint(syntheticParam)) {
65493
+ var targetConstraintString = typeToString(target, source.symbol.declarations[0]);
65494
+ associateRelatedInfo(ts.createDiagnosticForNode(source.symbol.declarations[0], ts.Diagnostics.This_type_parameter_might_need_an_extends_0_constraint, targetConstraintString));
65495
+ }
65485
65496
  }
65486
65497
  }
65487
65498
  function traceUnionsOrIntersectionsTooLarge(source, target) {
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.8.0-dev.20220615",
5
+ "version": "4.8.0-dev.20220616",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [