typescript 4.8.0-dev.20220614 → 4.8.0-dev.20220615

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/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.20220614";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220615";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -9156,6 +9156,8 @@ var ts;
9156
9156
  This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value: diag(2839, ts.DiagnosticCategory.Error, "This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value_2839", "This condition will always return '{0}' since JavaScript compares objects by reference, not value."),
9157
9157
  An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_classes: diag(2840, ts.DiagnosticCategory.Error, "An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_clas_2840", "An interface cannot extend a primitive type like '{0}'; an interface can only extend named types and classes"),
9158
9158
  The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."),
9159
+ _0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation: diag(2842, ts.DiagnosticCategory.Error, "_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation_2842", "'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?"),
9160
+ We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here: diag(2843, ts.DiagnosticCategory.Error, "We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here_2843", "We can only write a type for '{0}' by adding a type for the entire parameter here."),
9159
9161
  Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
9160
9162
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
9161
9163
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -49387,6 +49389,7 @@ var ts;
49387
49389
  var potentialNewTargetCollisions = [];
49388
49390
  var potentialWeakMapSetCollisions = [];
49389
49391
  var potentialReflectCollisions = [];
49392
+ var potentialUnusedRenamedBindingElementsInTypes = [];
49390
49393
  var awaitedTypeStack = [];
49391
49394
  var diagnostics = ts.createDiagnosticCollection();
49392
49395
  var suggestionDiagnostics = ts.createDiagnosticCollection();
@@ -53894,15 +53897,22 @@ var ts;
53894
53897
  context.approximateLength += ts.symbolName(parameterSymbol).length + 3;
53895
53898
  return parameterNode;
53896
53899
  function cloneBindingName(node) {
53897
- return elideInitializerAndSetEmitFlags(node);
53898
- function elideInitializerAndSetEmitFlags(node) {
53900
+ return elideInitializerAndPropertyRenamingAndSetEmitFlags(node);
53901
+ function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) {
53899
53902
  if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) {
53900
53903
  trackComputedName(node.expression, context.enclosingDeclaration, context);
53901
53904
  }
53902
- var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags);
53905
+ var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags);
53903
53906
  if (ts.isBindingElement(visited)) {
53904
- visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name,
53905
- /*initializer*/ undefined);
53907
+ if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) {
53908
+ visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken,
53909
+ /* propertyName*/ undefined, visited.propertyName,
53910
+ /*initializer*/ undefined);
53911
+ }
53912
+ else {
53913
+ visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name,
53914
+ /*initializer*/ undefined);
53915
+ }
53906
53916
  }
53907
53917
  if (!ts.nodeIsSynthesized(visited)) {
53908
53918
  visited = ts.factory.cloneNode(visited);
@@ -68226,12 +68236,13 @@ var ts;
68226
68236
  * with no call or construct signatures.
68227
68237
  */
68228
68238
  function isObjectTypeWithInferableIndex(type) {
68239
+ var objectFlags = ts.getObjectFlags(type);
68229
68240
  return type.flags & 2097152 /* Intersection */
68230
68241
  ? ts.every(type.types, isObjectTypeWithInferableIndex)
68231
68242
  : !!(type.symbol
68232
68243
  && (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0
68233
68244
  && !(type.symbol.flags & 32 /* Class */)
68234
- && !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
68245
+ && !typeHasCallOrConstructSignatures(type)) || !!(objectFlags & 4194304 /* ObjectRestType */) || !!(objectFlags & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
68235
68246
  }
68236
68247
  function createSymbolWithType(source, type) {
68237
68248
  var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
@@ -82830,6 +82841,22 @@ var ts;
82830
82841
  }
82831
82842
  });
82832
82843
  }
82844
+ function checkPotentialUncheckedRenamedBindingElementsInTypes() {
82845
+ var _a;
82846
+ for (var _i = 0, potentialUnusedRenamedBindingElementsInTypes_1 = potentialUnusedRenamedBindingElementsInTypes; _i < potentialUnusedRenamedBindingElementsInTypes_1.length; _i++) {
82847
+ var node = potentialUnusedRenamedBindingElementsInTypes_1[_i];
82848
+ if (!((_a = getSymbolOfNode(node)) === null || _a === void 0 ? void 0 : _a.isReferenced)) {
82849
+ var wrappingDeclaration = ts.walkUpBindingElementsAndPatterns(node);
82850
+ ts.Debug.assert(ts.isParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here");
82851
+ var diagnostic = ts.createDiagnosticForNode(node.name, ts.Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, ts.declarationNameToString(node.name), ts.declarationNameToString(node.propertyName));
82852
+ if (!wrappingDeclaration.type) {
82853
+ // entire parameter does not have type annotation, suggest adding an annotation
82854
+ ts.addRelatedInfo(diagnostic, ts.createFileDiagnostic(ts.getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end, 1, ts.Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, ts.declarationNameToString(node.propertyName)));
82855
+ }
82856
+ diagnostics.add(diagnostic);
82857
+ }
82858
+ }
82859
+ }
82833
82860
  function bindingNameText(name) {
82834
82861
  switch (name.kind) {
82835
82862
  case 79 /* Identifier */:
@@ -83131,6 +83158,17 @@ var ts;
83131
83158
  }
83132
83159
  }
83133
83160
  if (ts.isBindingElement(node)) {
83161
+ if (node.propertyName &&
83162
+ ts.isIdentifier(node.name) &&
83163
+ ts.isParameterDeclaration(node) &&
83164
+ ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
83165
+ // type F = ({a: string}) => void;
83166
+ // ^^^^^^
83167
+ // variable renaming in function type notation is confusing,
83168
+ // so we forbid it even if noUnusedLocals is not enabled
83169
+ potentialUnusedRenamedBindingElementsInTypes.push(node);
83170
+ return;
83171
+ }
83134
83172
  if (ts.isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < 5 /* ES2018 */) {
83135
83173
  checkExternalEmitHelpers(node, 4 /* Rest */);
83136
83174
  }
@@ -86594,6 +86632,7 @@ var ts;
86594
86632
  ts.clear(potentialNewTargetCollisions);
86595
86633
  ts.clear(potentialWeakMapSetCollisions);
86596
86634
  ts.clear(potentialReflectCollisions);
86635
+ ts.clear(potentialUnusedRenamedBindingElementsInTypes);
86597
86636
  ts.forEach(node.statements, checkSourceElement);
86598
86637
  checkSourceElement(node.endOfFileToken);
86599
86638
  checkDeferredNodes(node);
@@ -86609,6 +86648,9 @@ var ts;
86609
86648
  }
86610
86649
  });
86611
86650
  }
86651
+ if (!node.isDeclarationFile) {
86652
+ checkPotentialUncheckedRenamedBindingElementsInTypes();
86653
+ }
86612
86654
  });
86613
86655
  if (compilerOptions.importsNotUsedAsValues === 2 /* Error */ &&
86614
86656
  !node.isDeclarationFile &&
@@ -109350,7 +109392,7 @@ var ts;
109350
109392
  });
109351
109393
  return ret;
109352
109394
  }
109353
- function filterBindingPatternInitializers(name) {
109395
+ function filterBindingPatternInitializersAndRenamings(name) {
109354
109396
  if (name.kind === 79 /* Identifier */) {
109355
109397
  return name;
109356
109398
  }
@@ -109366,7 +109408,12 @@ var ts;
109366
109408
  if (elem.kind === 227 /* OmittedExpression */) {
109367
109409
  return elem;
109368
109410
  }
109369
- return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializers(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109411
+ if (elem.propertyName && ts.isIdentifier(elem.propertyName) && ts.isIdentifier(elem.name) && !elem.symbol.isReferenced) {
109412
+ // Unnecessary property renaming is forbidden in types, so remove renaming
109413
+ return factory.updateBindingElement(elem, elem.dotDotDotToken,
109414
+ /* propertyName */ undefined, elem.propertyName, shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109415
+ }
109416
+ return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializersAndRenamings(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109370
109417
  }
109371
109418
  }
109372
109419
  function ensureParameter(p, modifierMask, type) {
@@ -109375,7 +109422,7 @@ var ts;
109375
109422
  oldDiag = getSymbolAccessibilityDiagnostic;
109376
109423
  getSymbolAccessibilityDiagnostic = ts.createGetSymbolAccessibilityDiagnosticForNode(p);
109377
109424
  }
109378
- var newParam = factory.updateParameterDeclaration(p, maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializers(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(57 /* QuestionToken */)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
109425
+ var newParam = factory.updateParameterDeclaration(p, maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializersAndRenamings(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(57 /* QuestionToken */)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
109379
109426
  ensureNoInitializer(p));
109380
109427
  if (!suppressNewDiagnosticContexts) {
109381
109428
  getSymbolAccessibilityDiagnostic = oldDiag;
@@ -117518,6 +117565,7 @@ var ts;
117518
117565
  ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations.code,
117519
117566
  ts.Diagnostics.Class_constructor_may_not_be_a_generator.code,
117520
117567
  ts.Diagnostics.Class_constructor_may_not_be_an_accessor.code,
117568
+ ts.Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
117521
117569
  ]);
117522
117570
  /**
117523
117571
  * Determine if source file needs to be re-created even if its text hasn't 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.20220614";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220615";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -9156,6 +9156,8 @@ var ts;
9156
9156
  This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value: diag(2839, ts.DiagnosticCategory.Error, "This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value_2839", "This condition will always return '{0}' since JavaScript compares objects by reference, not value."),
9157
9157
  An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_classes: diag(2840, ts.DiagnosticCategory.Error, "An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_clas_2840", "An interface cannot extend a primitive type like '{0}'; an interface can only extend named types and classes"),
9158
9158
  The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."),
9159
+ _0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation: diag(2842, ts.DiagnosticCategory.Error, "_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation_2842", "'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?"),
9160
+ We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here: diag(2843, ts.DiagnosticCategory.Error, "We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here_2843", "We can only write a type for '{0}' by adding a type for the entire parameter here."),
9159
9161
  Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
9160
9162
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
9161
9163
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -49387,6 +49389,7 @@ var ts;
49387
49389
  var potentialNewTargetCollisions = [];
49388
49390
  var potentialWeakMapSetCollisions = [];
49389
49391
  var potentialReflectCollisions = [];
49392
+ var potentialUnusedRenamedBindingElementsInTypes = [];
49390
49393
  var awaitedTypeStack = [];
49391
49394
  var diagnostics = ts.createDiagnosticCollection();
49392
49395
  var suggestionDiagnostics = ts.createDiagnosticCollection();
@@ -53894,15 +53897,22 @@ var ts;
53894
53897
  context.approximateLength += ts.symbolName(parameterSymbol).length + 3;
53895
53898
  return parameterNode;
53896
53899
  function cloneBindingName(node) {
53897
- return elideInitializerAndSetEmitFlags(node);
53898
- function elideInitializerAndSetEmitFlags(node) {
53900
+ return elideInitializerAndPropertyRenamingAndSetEmitFlags(node);
53901
+ function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) {
53899
53902
  if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) {
53900
53903
  trackComputedName(node.expression, context.enclosingDeclaration, context);
53901
53904
  }
53902
- var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags);
53905
+ var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags);
53903
53906
  if (ts.isBindingElement(visited)) {
53904
- visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name,
53905
- /*initializer*/ undefined);
53907
+ if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) {
53908
+ visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken,
53909
+ /* propertyName*/ undefined, visited.propertyName,
53910
+ /*initializer*/ undefined);
53911
+ }
53912
+ else {
53913
+ visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name,
53914
+ /*initializer*/ undefined);
53915
+ }
53906
53916
  }
53907
53917
  if (!ts.nodeIsSynthesized(visited)) {
53908
53918
  visited = ts.factory.cloneNode(visited);
@@ -68226,12 +68236,13 @@ var ts;
68226
68236
  * with no call or construct signatures.
68227
68237
  */
68228
68238
  function isObjectTypeWithInferableIndex(type) {
68239
+ var objectFlags = ts.getObjectFlags(type);
68229
68240
  return type.flags & 2097152 /* Intersection */
68230
68241
  ? ts.every(type.types, isObjectTypeWithInferableIndex)
68231
68242
  : !!(type.symbol
68232
68243
  && (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0
68233
68244
  && !(type.symbol.flags & 32 /* Class */)
68234
- && !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
68245
+ && !typeHasCallOrConstructSignatures(type)) || !!(objectFlags & 4194304 /* ObjectRestType */) || !!(objectFlags & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
68235
68246
  }
68236
68247
  function createSymbolWithType(source, type) {
68237
68248
  var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
@@ -82830,6 +82841,22 @@ var ts;
82830
82841
  }
82831
82842
  });
82832
82843
  }
82844
+ function checkPotentialUncheckedRenamedBindingElementsInTypes() {
82845
+ var _a;
82846
+ for (var _i = 0, potentialUnusedRenamedBindingElementsInTypes_1 = potentialUnusedRenamedBindingElementsInTypes; _i < potentialUnusedRenamedBindingElementsInTypes_1.length; _i++) {
82847
+ var node = potentialUnusedRenamedBindingElementsInTypes_1[_i];
82848
+ if (!((_a = getSymbolOfNode(node)) === null || _a === void 0 ? void 0 : _a.isReferenced)) {
82849
+ var wrappingDeclaration = ts.walkUpBindingElementsAndPatterns(node);
82850
+ ts.Debug.assert(ts.isParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here");
82851
+ var diagnostic = ts.createDiagnosticForNode(node.name, ts.Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, ts.declarationNameToString(node.name), ts.declarationNameToString(node.propertyName));
82852
+ if (!wrappingDeclaration.type) {
82853
+ // entire parameter does not have type annotation, suggest adding an annotation
82854
+ ts.addRelatedInfo(diagnostic, ts.createFileDiagnostic(ts.getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end, 1, ts.Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, ts.declarationNameToString(node.propertyName)));
82855
+ }
82856
+ diagnostics.add(diagnostic);
82857
+ }
82858
+ }
82859
+ }
82833
82860
  function bindingNameText(name) {
82834
82861
  switch (name.kind) {
82835
82862
  case 79 /* Identifier */:
@@ -83131,6 +83158,17 @@ var ts;
83131
83158
  }
83132
83159
  }
83133
83160
  if (ts.isBindingElement(node)) {
83161
+ if (node.propertyName &&
83162
+ ts.isIdentifier(node.name) &&
83163
+ ts.isParameterDeclaration(node) &&
83164
+ ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
83165
+ // type F = ({a: string}) => void;
83166
+ // ^^^^^^
83167
+ // variable renaming in function type notation is confusing,
83168
+ // so we forbid it even if noUnusedLocals is not enabled
83169
+ potentialUnusedRenamedBindingElementsInTypes.push(node);
83170
+ return;
83171
+ }
83134
83172
  if (ts.isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < 5 /* ES2018 */) {
83135
83173
  checkExternalEmitHelpers(node, 4 /* Rest */);
83136
83174
  }
@@ -86594,6 +86632,7 @@ var ts;
86594
86632
  ts.clear(potentialNewTargetCollisions);
86595
86633
  ts.clear(potentialWeakMapSetCollisions);
86596
86634
  ts.clear(potentialReflectCollisions);
86635
+ ts.clear(potentialUnusedRenamedBindingElementsInTypes);
86597
86636
  ts.forEach(node.statements, checkSourceElement);
86598
86637
  checkSourceElement(node.endOfFileToken);
86599
86638
  checkDeferredNodes(node);
@@ -86609,6 +86648,9 @@ var ts;
86609
86648
  }
86610
86649
  });
86611
86650
  }
86651
+ if (!node.isDeclarationFile) {
86652
+ checkPotentialUncheckedRenamedBindingElementsInTypes();
86653
+ }
86612
86654
  });
86613
86655
  if (compilerOptions.importsNotUsedAsValues === 2 /* Error */ &&
86614
86656
  !node.isDeclarationFile &&
@@ -109350,7 +109392,7 @@ var ts;
109350
109392
  });
109351
109393
  return ret;
109352
109394
  }
109353
- function filterBindingPatternInitializers(name) {
109395
+ function filterBindingPatternInitializersAndRenamings(name) {
109354
109396
  if (name.kind === 79 /* Identifier */) {
109355
109397
  return name;
109356
109398
  }
@@ -109366,7 +109408,12 @@ var ts;
109366
109408
  if (elem.kind === 227 /* OmittedExpression */) {
109367
109409
  return elem;
109368
109410
  }
109369
- return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializers(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109411
+ if (elem.propertyName && ts.isIdentifier(elem.propertyName) && ts.isIdentifier(elem.name) && !elem.symbol.isReferenced) {
109412
+ // Unnecessary property renaming is forbidden in types, so remove renaming
109413
+ return factory.updateBindingElement(elem, elem.dotDotDotToken,
109414
+ /* propertyName */ undefined, elem.propertyName, shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109415
+ }
109416
+ return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializersAndRenamings(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109370
109417
  }
109371
109418
  }
109372
109419
  function ensureParameter(p, modifierMask, type) {
@@ -109375,7 +109422,7 @@ var ts;
109375
109422
  oldDiag = getSymbolAccessibilityDiagnostic;
109376
109423
  getSymbolAccessibilityDiagnostic = ts.createGetSymbolAccessibilityDiagnosticForNode(p);
109377
109424
  }
109378
- var newParam = factory.updateParameterDeclaration(p, maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializers(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(57 /* QuestionToken */)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
109425
+ var newParam = factory.updateParameterDeclaration(p, maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializersAndRenamings(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(57 /* QuestionToken */)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
109379
109426
  ensureNoInitializer(p));
109380
109427
  if (!suppressNewDiagnosticContexts) {
109381
109428
  getSymbolAccessibilityDiagnostic = oldDiag;
@@ -117518,6 +117565,7 @@ var ts;
117518
117565
  ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations.code,
117519
117566
  ts.Diagnostics.Class_constructor_may_not_be_a_generator.code,
117520
117567
  ts.Diagnostics.Class_constructor_may_not_be_an_accessor.code,
117568
+ ts.Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
117521
117569
  ]);
117522
117570
  /**
117523
117571
  * Determine if source file needs to be re-created even if its text hasn't changed
@@ -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.20220614";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220615";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -8951,6 +8951,8 @@ var ts;
8951
8951
  This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value: diag(2839, ts.DiagnosticCategory.Error, "This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value_2839", "This condition will always return '{0}' since JavaScript compares objects by reference, not value."),
8952
8952
  An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_classes: diag(2840, ts.DiagnosticCategory.Error, "An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_clas_2840", "An interface cannot extend a primitive type like '{0}'; an interface can only extend named types and classes"),
8953
8953
  The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."),
8954
+ _0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation: diag(2842, ts.DiagnosticCategory.Error, "_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation_2842", "'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?"),
8955
+ We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here: diag(2843, ts.DiagnosticCategory.Error, "We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here_2843", "We can only write a type for '{0}' by adding a type for the entire parameter here."),
8954
8956
  Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
8955
8957
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
8956
8958
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -49182,6 +49184,7 @@ var ts;
49182
49184
  var potentialNewTargetCollisions = [];
49183
49185
  var potentialWeakMapSetCollisions = [];
49184
49186
  var potentialReflectCollisions = [];
49187
+ var potentialUnusedRenamedBindingElementsInTypes = [];
49185
49188
  var awaitedTypeStack = [];
49186
49189
  var diagnostics = ts.createDiagnosticCollection();
49187
49190
  var suggestionDiagnostics = ts.createDiagnosticCollection();
@@ -53689,15 +53692,22 @@ var ts;
53689
53692
  context.approximateLength += ts.symbolName(parameterSymbol).length + 3;
53690
53693
  return parameterNode;
53691
53694
  function cloneBindingName(node) {
53692
- return elideInitializerAndSetEmitFlags(node);
53693
- function elideInitializerAndSetEmitFlags(node) {
53695
+ return elideInitializerAndPropertyRenamingAndSetEmitFlags(node);
53696
+ function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) {
53694
53697
  if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) {
53695
53698
  trackComputedName(node.expression, context.enclosingDeclaration, context);
53696
53699
  }
53697
- var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags);
53700
+ var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags);
53698
53701
  if (ts.isBindingElement(visited)) {
53699
- visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name,
53700
- /*initializer*/ undefined);
53702
+ if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) {
53703
+ visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken,
53704
+ /* propertyName*/ undefined, visited.propertyName,
53705
+ /*initializer*/ undefined);
53706
+ }
53707
+ else {
53708
+ visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name,
53709
+ /*initializer*/ undefined);
53710
+ }
53701
53711
  }
53702
53712
  if (!ts.nodeIsSynthesized(visited)) {
53703
53713
  visited = ts.factory.cloneNode(visited);
@@ -68021,12 +68031,13 @@ var ts;
68021
68031
  * with no call or construct signatures.
68022
68032
  */
68023
68033
  function isObjectTypeWithInferableIndex(type) {
68034
+ var objectFlags = ts.getObjectFlags(type);
68024
68035
  return type.flags & 2097152 /* Intersection */
68025
68036
  ? ts.every(type.types, isObjectTypeWithInferableIndex)
68026
68037
  : !!(type.symbol
68027
68038
  && (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0
68028
68039
  && !(type.symbol.flags & 32 /* Class */)
68029
- && !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
68040
+ && !typeHasCallOrConstructSignatures(type)) || !!(objectFlags & 4194304 /* ObjectRestType */) || !!(objectFlags & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
68030
68041
  }
68031
68042
  function createSymbolWithType(source, type) {
68032
68043
  var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
@@ -82625,6 +82636,22 @@ var ts;
82625
82636
  }
82626
82637
  });
82627
82638
  }
82639
+ function checkPotentialUncheckedRenamedBindingElementsInTypes() {
82640
+ var _a;
82641
+ for (var _i = 0, potentialUnusedRenamedBindingElementsInTypes_1 = potentialUnusedRenamedBindingElementsInTypes; _i < potentialUnusedRenamedBindingElementsInTypes_1.length; _i++) {
82642
+ var node = potentialUnusedRenamedBindingElementsInTypes_1[_i];
82643
+ if (!((_a = getSymbolOfNode(node)) === null || _a === void 0 ? void 0 : _a.isReferenced)) {
82644
+ var wrappingDeclaration = ts.walkUpBindingElementsAndPatterns(node);
82645
+ ts.Debug.assert(ts.isParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here");
82646
+ var diagnostic = ts.createDiagnosticForNode(node.name, ts.Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, ts.declarationNameToString(node.name), ts.declarationNameToString(node.propertyName));
82647
+ if (!wrappingDeclaration.type) {
82648
+ // entire parameter does not have type annotation, suggest adding an annotation
82649
+ ts.addRelatedInfo(diagnostic, ts.createFileDiagnostic(ts.getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end, 1, ts.Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, ts.declarationNameToString(node.propertyName)));
82650
+ }
82651
+ diagnostics.add(diagnostic);
82652
+ }
82653
+ }
82654
+ }
82628
82655
  function bindingNameText(name) {
82629
82656
  switch (name.kind) {
82630
82657
  case 79 /* Identifier */:
@@ -82926,6 +82953,17 @@ var ts;
82926
82953
  }
82927
82954
  }
82928
82955
  if (ts.isBindingElement(node)) {
82956
+ if (node.propertyName &&
82957
+ ts.isIdentifier(node.name) &&
82958
+ ts.isParameterDeclaration(node) &&
82959
+ ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
82960
+ // type F = ({a: string}) => void;
82961
+ // ^^^^^^
82962
+ // variable renaming in function type notation is confusing,
82963
+ // so we forbid it even if noUnusedLocals is not enabled
82964
+ potentialUnusedRenamedBindingElementsInTypes.push(node);
82965
+ return;
82966
+ }
82929
82967
  if (ts.isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < 5 /* ES2018 */) {
82930
82968
  checkExternalEmitHelpers(node, 4 /* Rest */);
82931
82969
  }
@@ -86389,6 +86427,7 @@ var ts;
86389
86427
  ts.clear(potentialNewTargetCollisions);
86390
86428
  ts.clear(potentialWeakMapSetCollisions);
86391
86429
  ts.clear(potentialReflectCollisions);
86430
+ ts.clear(potentialUnusedRenamedBindingElementsInTypes);
86392
86431
  ts.forEach(node.statements, checkSourceElement);
86393
86432
  checkSourceElement(node.endOfFileToken);
86394
86433
  checkDeferredNodes(node);
@@ -86404,6 +86443,9 @@ var ts;
86404
86443
  }
86405
86444
  });
86406
86445
  }
86446
+ if (!node.isDeclarationFile) {
86447
+ checkPotentialUncheckedRenamedBindingElementsInTypes();
86448
+ }
86407
86449
  });
86408
86450
  if (compilerOptions.importsNotUsedAsValues === 2 /* Error */ &&
86409
86451
  !node.isDeclarationFile &&
@@ -109145,7 +109187,7 @@ var ts;
109145
109187
  });
109146
109188
  return ret;
109147
109189
  }
109148
- function filterBindingPatternInitializers(name) {
109190
+ function filterBindingPatternInitializersAndRenamings(name) {
109149
109191
  if (name.kind === 79 /* Identifier */) {
109150
109192
  return name;
109151
109193
  }
@@ -109161,7 +109203,12 @@ var ts;
109161
109203
  if (elem.kind === 227 /* OmittedExpression */) {
109162
109204
  return elem;
109163
109205
  }
109164
- return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializers(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109206
+ if (elem.propertyName && ts.isIdentifier(elem.propertyName) && ts.isIdentifier(elem.name) && !elem.symbol.isReferenced) {
109207
+ // Unnecessary property renaming is forbidden in types, so remove renaming
109208
+ return factory.updateBindingElement(elem, elem.dotDotDotToken,
109209
+ /* propertyName */ undefined, elem.propertyName, shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109210
+ }
109211
+ return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializersAndRenamings(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
109165
109212
  }
109166
109213
  }
109167
109214
  function ensureParameter(p, modifierMask, type) {
@@ -109170,7 +109217,7 @@ var ts;
109170
109217
  oldDiag = getSymbolAccessibilityDiagnostic;
109171
109218
  getSymbolAccessibilityDiagnostic = ts.createGetSymbolAccessibilityDiagnosticForNode(p);
109172
109219
  }
109173
- var newParam = factory.updateParameterDeclaration(p, maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializers(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(57 /* QuestionToken */)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
109220
+ var newParam = factory.updateParameterDeclaration(p, maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializersAndRenamings(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(57 /* QuestionToken */)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
109174
109221
  ensureNoInitializer(p));
109175
109222
  if (!suppressNewDiagnosticContexts) {
109176
109223
  getSymbolAccessibilityDiagnostic = oldDiag;
@@ -117313,6 +117360,7 @@ var ts;
117313
117360
  ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations.code,
117314
117361
  ts.Diagnostics.Class_constructor_may_not_be_a_generator.code,
117315
117362
  ts.Diagnostics.Class_constructor_may_not_be_an_accessor.code,
117363
+ ts.Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
117316
117364
  ]);
117317
117365
  /**
117318
117366
  * Determine if source file needs to be re-created even if its text hasn't changed
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.20220614",
5
+ "version": "4.8.0-dev.20220615",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [
@@ -33,6 +33,7 @@
33
33
  "@octokit/rest": "latest",
34
34
  "@types/chai": "latest",
35
35
  "@types/convert-source-map": "latest",
36
+ "@types/fs-extra": "^9.0.13",
36
37
  "@types/glob": "latest",
37
38
  "@types/gulp": "^4.0.9",
38
39
  "@types/gulp-concat": "latest",