typescript 4.8.0-dev.20220524 → 4.8.0-dev.20220525

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.20220524";
72
+ ts.version = ts.versionMajorMinor + ".0-dev.20220525";
73
73
  var NativeCollections;
74
74
  (function (NativeCollections) {
75
75
  var globals = typeof globalThis !== "undefined" ? globalThis :
@@ -60320,7 +60320,7 @@ var ts;
60320
60320
  if (result) {
60321
60321
  return result;
60322
60322
  }
60323
- if (!(contextFlags & 8) && ts.isBindingPattern(declaration.name)) {
60323
+ if (!(contextFlags & 8) && ts.isBindingPattern(declaration.name) && declaration.name.elements.length > 0) {
60324
60324
  return getTypeFromBindingPattern(declaration.name, true, false);
60325
60325
  }
60326
60326
  }
@@ -60737,16 +60737,14 @@ var ts;
60737
60737
  function instantiateContextualType(contextualType, node, contextFlags) {
60738
60738
  if (contextualType && maybeTypeOfKind(contextualType, 465829888)) {
60739
60739
  var inferenceContext = getInferenceContext(node);
60740
- if (inferenceContext && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
60741
- if (contextFlags && contextFlags & 1) {
60742
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
60743
- }
60744
- if (inferenceContext.returnMapper) {
60745
- var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
60746
- return type.flags & 1048576 && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
60747
- filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
60748
- type;
60749
- }
60740
+ if (inferenceContext && contextFlags & 1 && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
60741
+ return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
60742
+ }
60743
+ if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnMapper) {
60744
+ var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
60745
+ return type.flags & 1048576 && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
60746
+ filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
60747
+ type;
60750
60748
  }
60751
60749
  }
60752
60750
  return contextualType;
@@ -62900,18 +62898,22 @@ var ts;
62900
62898
  return inferJsxTypeArguments(node, signature, checkMode, context);
62901
62899
  }
62902
62900
  if (node.kind !== 165) {
62903
- var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 : 0);
62901
+ var skipBindingPatterns = ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); });
62902
+ var contextualType = getContextualType(node, skipBindingPatterns ? 8 : 0);
62904
62903
  if (contextualType) {
62905
62904
  var inferenceTargetType = getReturnTypeOfSignature(signature);
62906
62905
  if (couldContainTypeVariables(inferenceTargetType)) {
62907
62906
  var outerContext = getInferenceContext(node);
62908
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1));
62909
- var instantiatedType = instantiateType(contextualType, outerMapper);
62910
- var contextualSignature = getSingleCallSignature(instantiatedType);
62911
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
62912
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
62913
- instantiatedType;
62914
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128);
62907
+ var isFromBindingPattern = !skipBindingPatterns && getContextualType(node, 8) !== contextualType;
62908
+ if (!isFromBindingPattern) {
62909
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1));
62910
+ var instantiatedType = instantiateType(contextualType, outerMapper);
62911
+ var contextualSignature = getSingleCallSignature(instantiatedType);
62912
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
62913
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
62914
+ instantiatedType;
62915
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128);
62916
+ }
62915
62917
  var returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
62916
62918
  var returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
62917
62919
  inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
@@ -87835,7 +87837,7 @@ var ts;
87835
87837
  function visitor(node) {
87836
87838
  switch (node.kind) {
87837
87839
  case 265:
87838
- return ts.getEmitScriptTarget(compilerOptions) >= ts.ModuleKind.ES2020 ? visitImportEqualsDeclaration(node) : undefined;
87840
+ return ts.getEmitModuleKind(compilerOptions) >= ts.ModuleKind.Node16 ? visitImportEqualsDeclaration(node) : undefined;
87839
87841
  case 271:
87840
87842
  return visitExportAssignment(node);
87841
87843
  case 272:
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220524";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220525";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -72296,7 +72296,7 @@ var ts;
72296
72296
  if (result) {
72297
72297
  return result;
72298
72298
  }
72299
- if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable
72299
+ if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name) && declaration.name.elements.length > 0) {
72300
72300
  return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
72301
72301
  }
72302
72302
  }
@@ -72765,22 +72765,20 @@ var ts;
72765
72765
  var inferenceContext = getInferenceContext(node);
72766
72766
  // If no inferences have been made, nothing is gained from instantiating as type parameters
72767
72767
  // would just be replaced with their defaults similar to the apparent type.
72768
- if (inferenceContext && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72768
+ if (inferenceContext && contextFlags & 1 /* Signature */ && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72769
72769
  // For contextual signatures we incorporate all inferences made so far, e.g. from return
72770
72770
  // types as well as arguments to the left in a function call.
72771
- if (contextFlags && contextFlags & 1 /* Signature */) {
72772
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72773
- }
72771
+ return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72772
+ }
72773
+ if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnMapper) {
72774
72774
  // For other purposes (e.g. determining whether to produce literal types) we only
72775
72775
  // incorporate inferences made from the return type in a function call. We remove
72776
72776
  // the 'boolean' type from the contextual type such that contextually typed boolean
72777
72777
  // literals actually end up widening to 'boolean' (see #48363).
72778
- if (inferenceContext.returnMapper) {
72779
- var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72780
- return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72781
- filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72782
- type;
72783
- }
72778
+ var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72779
+ return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72780
+ filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72781
+ type;
72784
72782
  }
72785
72783
  }
72786
72784
  return contextualType;
@@ -75314,29 +75312,43 @@ var ts;
75314
75312
  // 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
75315
75313
  // return type of 'wrap'.
75316
75314
  if (node.kind !== 165 /* Decorator */) {
75317
- var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75315
+ var skipBindingPatterns = ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); });
75316
+ var contextualType = getContextualType(node, skipBindingPatterns ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75318
75317
  if (contextualType) {
75319
75318
  var inferenceTargetType = getReturnTypeOfSignature(signature);
75320
75319
  if (couldContainTypeVariables(inferenceTargetType)) {
75321
- // We clone the inference context to avoid disturbing a resolution in progress for an
75322
- // outer call expression. Effectively we just want a snapshot of whatever has been
75323
- // inferred for any outer call expression so far.
75324
75320
  var outerContext = getInferenceContext(node);
75325
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75326
- var instantiatedType = instantiateType(contextualType, outerMapper);
75327
- // If the contextual type is a generic function type with a single call signature, we
75328
- // instantiate the type with its own type parameters and type arguments. This ensures that
75329
- // the type parameters are not erased to type any during type inference such that they can
75330
- // be inferred as actual types from the contextual type. For example:
75331
- // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75332
- // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75333
- // Above, the type of the 'value' parameter is inferred to be 'A'.
75334
- var contextualSignature = getSingleCallSignature(instantiatedType);
75335
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75336
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75337
- instantiatedType;
75338
- // Inferences made from return types have lower priority than all other inferences.
75339
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75321
+ var isFromBindingPattern = !skipBindingPatterns && getContextualType(node, 8 /* SkipBindingPatterns */) !== contextualType;
75322
+ // A return type inference from a binding pattern can be used in instantiating the contextual
75323
+ // type of an argument later in inference, but cannot stand on its own as the final return type.
75324
+ // It is incorporated into `context.returnMapper` which is used in `instantiateContextualType`,
75325
+ // but doesn't need to go into `context.inferences`. This allows a an array binding pattern to
75326
+ // produce a tuple for `T` in
75327
+ // declare function f<T>(cb: () => T): T;
75328
+ // const [e1, e2, e3] = f(() => [1, "hi", true]);
75329
+ // but does not produce any inference for `T` in
75330
+ // declare function f<T>(): T;
75331
+ // const [e1, e2, e3] = f();
75332
+ if (!isFromBindingPattern) {
75333
+ // We clone the inference context to avoid disturbing a resolution in progress for an
75334
+ // outer call expression. Effectively we just want a snapshot of whatever has been
75335
+ // inferred for any outer call expression so far.
75336
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75337
+ var instantiatedType = instantiateType(contextualType, outerMapper);
75338
+ // If the contextual type is a generic function type with a single call signature, we
75339
+ // instantiate the type with its own type parameters and type arguments. This ensures that
75340
+ // the type parameters are not erased to type any during type inference such that they can
75341
+ // be inferred as actual types from the contextual type. For example:
75342
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75343
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75344
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
75345
+ var contextualSignature = getSingleCallSignature(instantiatedType);
75346
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75347
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75348
+ instantiatedType;
75349
+ // Inferences made from return types have lower priority than all other inferences.
75350
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75351
+ }
75340
75352
  // Create a type mapper for instantiating generic contextual types using the inferences made
75341
75353
  // from the return type. We need a separate inference pass here because (a) instantiation of
75342
75354
  // the source type uses the outer context's return mapper (which excludes inferences made from
@@ -107261,7 +107273,7 @@ var ts;
107261
107273
  // Though an error in es2020 modules, in node-flavor es2020 modules, we can helpfully transform this to a synthetic `require` call
107262
107274
  // To give easy access to a synchronous `require` in node-flavor esm. We do the transform even in scenarios where we error, but `import.meta.url`
107263
107275
  // is available, just because the output is reasonable for a node-like runtime.
107264
- return ts.getEmitScriptTarget(compilerOptions) >= ts.ModuleKind.ES2020 ? visitImportEqualsDeclaration(node) : undefined;
107276
+ return ts.getEmitModuleKind(compilerOptions) >= ts.ModuleKind.Node16 ? visitImportEqualsDeclaration(node) : undefined;
107265
107277
  case 271 /* ExportAssignment */:
107266
107278
  return visitExportAssignment(node);
107267
107279
  case 272 /* ExportDeclaration */:
@@ -134698,6 +134710,7 @@ var ts;
134698
134710
  return kind === 131 /* AsyncKeyword */
134699
134711
  || kind === 132 /* AwaitKeyword */
134700
134712
  || kind === 127 /* AsKeyword */
134713
+ || kind === 152 /* TypeKeyword */
134701
134714
  || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
134702
134715
  }
134703
134716
  function keywordForNode(node) {
@@ -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.20220524";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220525";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -72490,7 +72490,7 @@ var ts;
72490
72490
  if (result) {
72491
72491
  return result;
72492
72492
  }
72493
- if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable
72493
+ if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name) && declaration.name.elements.length > 0) {
72494
72494
  return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
72495
72495
  }
72496
72496
  }
@@ -72959,22 +72959,20 @@ var ts;
72959
72959
  var inferenceContext = getInferenceContext(node);
72960
72960
  // If no inferences have been made, nothing is gained from instantiating as type parameters
72961
72961
  // would just be replaced with their defaults similar to the apparent type.
72962
- if (inferenceContext && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72962
+ if (inferenceContext && contextFlags & 1 /* Signature */ && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72963
72963
  // For contextual signatures we incorporate all inferences made so far, e.g. from return
72964
72964
  // types as well as arguments to the left in a function call.
72965
- if (contextFlags && contextFlags & 1 /* Signature */) {
72966
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72967
- }
72965
+ return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72966
+ }
72967
+ if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnMapper) {
72968
72968
  // For other purposes (e.g. determining whether to produce literal types) we only
72969
72969
  // incorporate inferences made from the return type in a function call. We remove
72970
72970
  // the 'boolean' type from the contextual type such that contextually typed boolean
72971
72971
  // literals actually end up widening to 'boolean' (see #48363).
72972
- if (inferenceContext.returnMapper) {
72973
- var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72974
- return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72975
- filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72976
- type;
72977
- }
72972
+ var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72973
+ return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72974
+ filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72975
+ type;
72978
72976
  }
72979
72977
  }
72980
72978
  return contextualType;
@@ -75508,29 +75506,43 @@ var ts;
75508
75506
  // 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
75509
75507
  // return type of 'wrap'.
75510
75508
  if (node.kind !== 165 /* Decorator */) {
75511
- var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75509
+ var skipBindingPatterns = ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); });
75510
+ var contextualType = getContextualType(node, skipBindingPatterns ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75512
75511
  if (contextualType) {
75513
75512
  var inferenceTargetType = getReturnTypeOfSignature(signature);
75514
75513
  if (couldContainTypeVariables(inferenceTargetType)) {
75515
- // We clone the inference context to avoid disturbing a resolution in progress for an
75516
- // outer call expression. Effectively we just want a snapshot of whatever has been
75517
- // inferred for any outer call expression so far.
75518
75514
  var outerContext = getInferenceContext(node);
75519
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75520
- var instantiatedType = instantiateType(contextualType, outerMapper);
75521
- // If the contextual type is a generic function type with a single call signature, we
75522
- // instantiate the type with its own type parameters and type arguments. This ensures that
75523
- // the type parameters are not erased to type any during type inference such that they can
75524
- // be inferred as actual types from the contextual type. For example:
75525
- // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75526
- // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75527
- // Above, the type of the 'value' parameter is inferred to be 'A'.
75528
- var contextualSignature = getSingleCallSignature(instantiatedType);
75529
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75530
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75531
- instantiatedType;
75532
- // Inferences made from return types have lower priority than all other inferences.
75533
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75515
+ var isFromBindingPattern = !skipBindingPatterns && getContextualType(node, 8 /* SkipBindingPatterns */) !== contextualType;
75516
+ // A return type inference from a binding pattern can be used in instantiating the contextual
75517
+ // type of an argument later in inference, but cannot stand on its own as the final return type.
75518
+ // It is incorporated into `context.returnMapper` which is used in `instantiateContextualType`,
75519
+ // but doesn't need to go into `context.inferences`. This allows a an array binding pattern to
75520
+ // produce a tuple for `T` in
75521
+ // declare function f<T>(cb: () => T): T;
75522
+ // const [e1, e2, e3] = f(() => [1, "hi", true]);
75523
+ // but does not produce any inference for `T` in
75524
+ // declare function f<T>(): T;
75525
+ // const [e1, e2, e3] = f();
75526
+ if (!isFromBindingPattern) {
75527
+ // We clone the inference context to avoid disturbing a resolution in progress for an
75528
+ // outer call expression. Effectively we just want a snapshot of whatever has been
75529
+ // inferred for any outer call expression so far.
75530
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75531
+ var instantiatedType = instantiateType(contextualType, outerMapper);
75532
+ // If the contextual type is a generic function type with a single call signature, we
75533
+ // instantiate the type with its own type parameters and type arguments. This ensures that
75534
+ // the type parameters are not erased to type any during type inference such that they can
75535
+ // be inferred as actual types from the contextual type. For example:
75536
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75537
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75538
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
75539
+ var contextualSignature = getSingleCallSignature(instantiatedType);
75540
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75541
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75542
+ instantiatedType;
75543
+ // Inferences made from return types have lower priority than all other inferences.
75544
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75545
+ }
75534
75546
  // Create a type mapper for instantiating generic contextual types using the inferences made
75535
75547
  // from the return type. We need a separate inference pass here because (a) instantiation of
75536
75548
  // the source type uses the outer context's return mapper (which excludes inferences made from
@@ -107455,7 +107467,7 @@ var ts;
107455
107467
  // Though an error in es2020 modules, in node-flavor es2020 modules, we can helpfully transform this to a synthetic `require` call
107456
107468
  // To give easy access to a synchronous `require` in node-flavor esm. We do the transform even in scenarios where we error, but `import.meta.url`
107457
107469
  // is available, just because the output is reasonable for a node-like runtime.
107458
- return ts.getEmitScriptTarget(compilerOptions) >= ts.ModuleKind.ES2020 ? visitImportEqualsDeclaration(node) : undefined;
107470
+ return ts.getEmitModuleKind(compilerOptions) >= ts.ModuleKind.Node16 ? visitImportEqualsDeclaration(node) : undefined;
107459
107471
  case 271 /* ExportAssignment */:
107460
107472
  return visitExportAssignment(node);
107461
107473
  case 272 /* ExportDeclaration */:
@@ -135309,6 +135321,7 @@ var ts;
135309
135321
  return kind === 131 /* AsyncKeyword */
135310
135322
  || kind === 132 /* AwaitKeyword */
135311
135323
  || kind === 127 /* AsKeyword */
135324
+ || kind === 152 /* TypeKeyword */
135312
135325
  || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
135313
135326
  }
135314
135327
  function keywordForNode(node) {
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.20220524";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220525";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -72490,7 +72490,7 @@ var ts;
72490
72490
  if (result) {
72491
72491
  return result;
72492
72492
  }
72493
- if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable
72493
+ if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name) && declaration.name.elements.length > 0) {
72494
72494
  return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
72495
72495
  }
72496
72496
  }
@@ -72959,22 +72959,20 @@ var ts;
72959
72959
  var inferenceContext = getInferenceContext(node);
72960
72960
  // If no inferences have been made, nothing is gained from instantiating as type parameters
72961
72961
  // would just be replaced with their defaults similar to the apparent type.
72962
- if (inferenceContext && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72962
+ if (inferenceContext && contextFlags & 1 /* Signature */ && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72963
72963
  // For contextual signatures we incorporate all inferences made so far, e.g. from return
72964
72964
  // types as well as arguments to the left in a function call.
72965
- if (contextFlags && contextFlags & 1 /* Signature */) {
72966
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72967
- }
72965
+ return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72966
+ }
72967
+ if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnMapper) {
72968
72968
  // For other purposes (e.g. determining whether to produce literal types) we only
72969
72969
  // incorporate inferences made from the return type in a function call. We remove
72970
72970
  // the 'boolean' type from the contextual type such that contextually typed boolean
72971
72971
  // literals actually end up widening to 'boolean' (see #48363).
72972
- if (inferenceContext.returnMapper) {
72973
- var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72974
- return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72975
- filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72976
- type;
72977
- }
72972
+ var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72973
+ return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72974
+ filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72975
+ type;
72978
72976
  }
72979
72977
  }
72980
72978
  return contextualType;
@@ -75508,29 +75506,43 @@ var ts;
75508
75506
  // 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
75509
75507
  // return type of 'wrap'.
75510
75508
  if (node.kind !== 165 /* Decorator */) {
75511
- var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75509
+ var skipBindingPatterns = ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); });
75510
+ var contextualType = getContextualType(node, skipBindingPatterns ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75512
75511
  if (contextualType) {
75513
75512
  var inferenceTargetType = getReturnTypeOfSignature(signature);
75514
75513
  if (couldContainTypeVariables(inferenceTargetType)) {
75515
- // We clone the inference context to avoid disturbing a resolution in progress for an
75516
- // outer call expression. Effectively we just want a snapshot of whatever has been
75517
- // inferred for any outer call expression so far.
75518
75514
  var outerContext = getInferenceContext(node);
75519
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75520
- var instantiatedType = instantiateType(contextualType, outerMapper);
75521
- // If the contextual type is a generic function type with a single call signature, we
75522
- // instantiate the type with its own type parameters and type arguments. This ensures that
75523
- // the type parameters are not erased to type any during type inference such that they can
75524
- // be inferred as actual types from the contextual type. For example:
75525
- // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75526
- // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75527
- // Above, the type of the 'value' parameter is inferred to be 'A'.
75528
- var contextualSignature = getSingleCallSignature(instantiatedType);
75529
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75530
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75531
- instantiatedType;
75532
- // Inferences made from return types have lower priority than all other inferences.
75533
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75515
+ var isFromBindingPattern = !skipBindingPatterns && getContextualType(node, 8 /* SkipBindingPatterns */) !== contextualType;
75516
+ // A return type inference from a binding pattern can be used in instantiating the contextual
75517
+ // type of an argument later in inference, but cannot stand on its own as the final return type.
75518
+ // It is incorporated into `context.returnMapper` which is used in `instantiateContextualType`,
75519
+ // but doesn't need to go into `context.inferences`. This allows a an array binding pattern to
75520
+ // produce a tuple for `T` in
75521
+ // declare function f<T>(cb: () => T): T;
75522
+ // const [e1, e2, e3] = f(() => [1, "hi", true]);
75523
+ // but does not produce any inference for `T` in
75524
+ // declare function f<T>(): T;
75525
+ // const [e1, e2, e3] = f();
75526
+ if (!isFromBindingPattern) {
75527
+ // We clone the inference context to avoid disturbing a resolution in progress for an
75528
+ // outer call expression. Effectively we just want a snapshot of whatever has been
75529
+ // inferred for any outer call expression so far.
75530
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75531
+ var instantiatedType = instantiateType(contextualType, outerMapper);
75532
+ // If the contextual type is a generic function type with a single call signature, we
75533
+ // instantiate the type with its own type parameters and type arguments. This ensures that
75534
+ // the type parameters are not erased to type any during type inference such that they can
75535
+ // be inferred as actual types from the contextual type. For example:
75536
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75537
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75538
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
75539
+ var contextualSignature = getSingleCallSignature(instantiatedType);
75540
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75541
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75542
+ instantiatedType;
75543
+ // Inferences made from return types have lower priority than all other inferences.
75544
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75545
+ }
75534
75546
  // Create a type mapper for instantiating generic contextual types using the inferences made
75535
75547
  // from the return type. We need a separate inference pass here because (a) instantiation of
75536
75548
  // the source type uses the outer context's return mapper (which excludes inferences made from
@@ -107455,7 +107467,7 @@ var ts;
107455
107467
  // Though an error in es2020 modules, in node-flavor es2020 modules, we can helpfully transform this to a synthetic `require` call
107456
107468
  // To give easy access to a synchronous `require` in node-flavor esm. We do the transform even in scenarios where we error, but `import.meta.url`
107457
107469
  // is available, just because the output is reasonable for a node-like runtime.
107458
- return ts.getEmitScriptTarget(compilerOptions) >= ts.ModuleKind.ES2020 ? visitImportEqualsDeclaration(node) : undefined;
107470
+ return ts.getEmitModuleKind(compilerOptions) >= ts.ModuleKind.Node16 ? visitImportEqualsDeclaration(node) : undefined;
107459
107471
  case 271 /* ExportAssignment */:
107460
107472
  return visitExportAssignment(node);
107461
107473
  case 272 /* ExportDeclaration */:
@@ -135309,6 +135321,7 @@ var ts;
135309
135321
  return kind === 131 /* AsyncKeyword */
135310
135322
  || kind === 132 /* AwaitKeyword */
135311
135323
  || kind === 127 /* AsKeyword */
135324
+ || kind === 152 /* TypeKeyword */
135312
135325
  || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
135313
135326
  }
135314
135327
  function keywordForNode(node) {
@@ -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.20220524";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220525";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -72490,7 +72490,7 @@ var ts;
72490
72490
  if (result) {
72491
72491
  return result;
72492
72492
  }
72493
- if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable
72493
+ if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name) && declaration.name.elements.length > 0) {
72494
72494
  return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
72495
72495
  }
72496
72496
  }
@@ -72959,22 +72959,20 @@ var ts;
72959
72959
  var inferenceContext = getInferenceContext(node);
72960
72960
  // If no inferences have been made, nothing is gained from instantiating as type parameters
72961
72961
  // would just be replaced with their defaults similar to the apparent type.
72962
- if (inferenceContext && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72962
+ if (inferenceContext && contextFlags & 1 /* Signature */ && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72963
72963
  // For contextual signatures we incorporate all inferences made so far, e.g. from return
72964
72964
  // types as well as arguments to the left in a function call.
72965
- if (contextFlags && contextFlags & 1 /* Signature */) {
72966
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72967
- }
72965
+ return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72966
+ }
72967
+ if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnMapper) {
72968
72968
  // For other purposes (e.g. determining whether to produce literal types) we only
72969
72969
  // incorporate inferences made from the return type in a function call. We remove
72970
72970
  // the 'boolean' type from the contextual type such that contextually typed boolean
72971
72971
  // literals actually end up widening to 'boolean' (see #48363).
72972
- if (inferenceContext.returnMapper) {
72973
- var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72974
- return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72975
- filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72976
- type;
72977
- }
72972
+ var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72973
+ return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72974
+ filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72975
+ type;
72978
72976
  }
72979
72977
  }
72980
72978
  return contextualType;
@@ -75508,29 +75506,43 @@ var ts;
75508
75506
  // 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
75509
75507
  // return type of 'wrap'.
75510
75508
  if (node.kind !== 165 /* Decorator */) {
75511
- var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75509
+ var skipBindingPatterns = ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); });
75510
+ var contextualType = getContextualType(node, skipBindingPatterns ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75512
75511
  if (contextualType) {
75513
75512
  var inferenceTargetType = getReturnTypeOfSignature(signature);
75514
75513
  if (couldContainTypeVariables(inferenceTargetType)) {
75515
- // We clone the inference context to avoid disturbing a resolution in progress for an
75516
- // outer call expression. Effectively we just want a snapshot of whatever has been
75517
- // inferred for any outer call expression so far.
75518
75514
  var outerContext = getInferenceContext(node);
75519
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75520
- var instantiatedType = instantiateType(contextualType, outerMapper);
75521
- // If the contextual type is a generic function type with a single call signature, we
75522
- // instantiate the type with its own type parameters and type arguments. This ensures that
75523
- // the type parameters are not erased to type any during type inference such that they can
75524
- // be inferred as actual types from the contextual type. For example:
75525
- // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75526
- // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75527
- // Above, the type of the 'value' parameter is inferred to be 'A'.
75528
- var contextualSignature = getSingleCallSignature(instantiatedType);
75529
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75530
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75531
- instantiatedType;
75532
- // Inferences made from return types have lower priority than all other inferences.
75533
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75515
+ var isFromBindingPattern = !skipBindingPatterns && getContextualType(node, 8 /* SkipBindingPatterns */) !== contextualType;
75516
+ // A return type inference from a binding pattern can be used in instantiating the contextual
75517
+ // type of an argument later in inference, but cannot stand on its own as the final return type.
75518
+ // It is incorporated into `context.returnMapper` which is used in `instantiateContextualType`,
75519
+ // but doesn't need to go into `context.inferences`. This allows a an array binding pattern to
75520
+ // produce a tuple for `T` in
75521
+ // declare function f<T>(cb: () => T): T;
75522
+ // const [e1, e2, e3] = f(() => [1, "hi", true]);
75523
+ // but does not produce any inference for `T` in
75524
+ // declare function f<T>(): T;
75525
+ // const [e1, e2, e3] = f();
75526
+ if (!isFromBindingPattern) {
75527
+ // We clone the inference context to avoid disturbing a resolution in progress for an
75528
+ // outer call expression. Effectively we just want a snapshot of whatever has been
75529
+ // inferred for any outer call expression so far.
75530
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75531
+ var instantiatedType = instantiateType(contextualType, outerMapper);
75532
+ // If the contextual type is a generic function type with a single call signature, we
75533
+ // instantiate the type with its own type parameters and type arguments. This ensures that
75534
+ // the type parameters are not erased to type any during type inference such that they can
75535
+ // be inferred as actual types from the contextual type. For example:
75536
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75537
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75538
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
75539
+ var contextualSignature = getSingleCallSignature(instantiatedType);
75540
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75541
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75542
+ instantiatedType;
75543
+ // Inferences made from return types have lower priority than all other inferences.
75544
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75545
+ }
75534
75546
  // Create a type mapper for instantiating generic contextual types using the inferences made
75535
75547
  // from the return type. We need a separate inference pass here because (a) instantiation of
75536
75548
  // the source type uses the outer context's return mapper (which excludes inferences made from
@@ -107455,7 +107467,7 @@ var ts;
107455
107467
  // Though an error in es2020 modules, in node-flavor es2020 modules, we can helpfully transform this to a synthetic `require` call
107456
107468
  // To give easy access to a synchronous `require` in node-flavor esm. We do the transform even in scenarios where we error, but `import.meta.url`
107457
107469
  // is available, just because the output is reasonable for a node-like runtime.
107458
- return ts.getEmitScriptTarget(compilerOptions) >= ts.ModuleKind.ES2020 ? visitImportEqualsDeclaration(node) : undefined;
107470
+ return ts.getEmitModuleKind(compilerOptions) >= ts.ModuleKind.Node16 ? visitImportEqualsDeclaration(node) : undefined;
107459
107471
  case 271 /* ExportAssignment */:
107460
107472
  return visitExportAssignment(node);
107461
107473
  case 272 /* ExportDeclaration */:
@@ -135309,6 +135321,7 @@ var ts;
135309
135321
  return kind === 131 /* AsyncKeyword */
135310
135322
  || kind === 132 /* AwaitKeyword */
135311
135323
  || kind === 127 /* AsKeyword */
135324
+ || kind === 152 /* TypeKeyword */
135312
135325
  || !ts.isContextualKeyword(kind) && !isClassMemberCompletionKeyword(kind);
135313
135326
  }
135314
135327
  function keywordForNode(node) {
@@ -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.20220524";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220525";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -72285,7 +72285,7 @@ var ts;
72285
72285
  if (result) {
72286
72286
  return result;
72287
72287
  }
72288
- if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable
72288
+ if (!(contextFlags & 8 /* SkipBindingPatterns */) && ts.isBindingPattern(declaration.name) && declaration.name.elements.length > 0) {
72289
72289
  return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
72290
72290
  }
72291
72291
  }
@@ -72754,22 +72754,20 @@ var ts;
72754
72754
  var inferenceContext = getInferenceContext(node);
72755
72755
  // If no inferences have been made, nothing is gained from instantiating as type parameters
72756
72756
  // would just be replaced with their defaults similar to the apparent type.
72757
- if (inferenceContext && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72757
+ if (inferenceContext && contextFlags & 1 /* Signature */ && ts.some(inferenceContext.inferences, hasInferenceCandidates)) {
72758
72758
  // For contextual signatures we incorporate all inferences made so far, e.g. from return
72759
72759
  // types as well as arguments to the left in a function call.
72760
- if (contextFlags && contextFlags & 1 /* Signature */) {
72761
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72762
- }
72760
+ return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
72761
+ }
72762
+ if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnMapper) {
72763
72763
  // For other purposes (e.g. determining whether to produce literal types) we only
72764
72764
  // incorporate inferences made from the return type in a function call. We remove
72765
72765
  // the 'boolean' type from the contextual type such that contextually typed boolean
72766
72766
  // literals actually end up widening to 'boolean' (see #48363).
72767
- if (inferenceContext.returnMapper) {
72768
- var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72769
- return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72770
- filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72771
- type;
72772
- }
72767
+ var type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
72768
+ return type.flags & 1048576 /* Union */ && containsType(type.types, regularFalseType) && containsType(type.types, regularTrueType) ?
72769
+ filterType(type, function (t) { return t !== regularFalseType && t !== regularTrueType; }) :
72770
+ type;
72773
72771
  }
72774
72772
  }
72775
72773
  return contextualType;
@@ -75303,29 +75301,43 @@ var ts;
75303
75301
  // 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
75304
75302
  // return type of 'wrap'.
75305
75303
  if (node.kind !== 165 /* Decorator */) {
75306
- var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75304
+ var skipBindingPatterns = ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); });
75305
+ var contextualType = getContextualType(node, skipBindingPatterns ? 8 /* SkipBindingPatterns */ : 0 /* None */);
75307
75306
  if (contextualType) {
75308
75307
  var inferenceTargetType = getReturnTypeOfSignature(signature);
75309
75308
  if (couldContainTypeVariables(inferenceTargetType)) {
75310
- // We clone the inference context to avoid disturbing a resolution in progress for an
75311
- // outer call expression. Effectively we just want a snapshot of whatever has been
75312
- // inferred for any outer call expression so far.
75313
75309
  var outerContext = getInferenceContext(node);
75314
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75315
- var instantiatedType = instantiateType(contextualType, outerMapper);
75316
- // If the contextual type is a generic function type with a single call signature, we
75317
- // instantiate the type with its own type parameters and type arguments. This ensures that
75318
- // the type parameters are not erased to type any during type inference such that they can
75319
- // be inferred as actual types from the contextual type. For example:
75320
- // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75321
- // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75322
- // Above, the type of the 'value' parameter is inferred to be 'A'.
75323
- var contextualSignature = getSingleCallSignature(instantiatedType);
75324
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75325
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75326
- instantiatedType;
75327
- // Inferences made from return types have lower priority than all other inferences.
75328
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75310
+ var isFromBindingPattern = !skipBindingPatterns && getContextualType(node, 8 /* SkipBindingPatterns */) !== contextualType;
75311
+ // A return type inference from a binding pattern can be used in instantiating the contextual
75312
+ // type of an argument later in inference, but cannot stand on its own as the final return type.
75313
+ // It is incorporated into `context.returnMapper` which is used in `instantiateContextualType`,
75314
+ // but doesn't need to go into `context.inferences`. This allows a an array binding pattern to
75315
+ // produce a tuple for `T` in
75316
+ // declare function f<T>(cb: () => T): T;
75317
+ // const [e1, e2, e3] = f(() => [1, "hi", true]);
75318
+ // but does not produce any inference for `T` in
75319
+ // declare function f<T>(): T;
75320
+ // const [e1, e2, e3] = f();
75321
+ if (!isFromBindingPattern) {
75322
+ // We clone the inference context to avoid disturbing a resolution in progress for an
75323
+ // outer call expression. Effectively we just want a snapshot of whatever has been
75324
+ // inferred for any outer call expression so far.
75325
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75326
+ var instantiatedType = instantiateType(contextualType, outerMapper);
75327
+ // If the contextual type is a generic function type with a single call signature, we
75328
+ // instantiate the type with its own type parameters and type arguments. This ensures that
75329
+ // the type parameters are not erased to type any during type inference such that they can
75330
+ // be inferred as actual types from the contextual type. For example:
75331
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75332
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75333
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
75334
+ var contextualSignature = getSingleCallSignature(instantiatedType);
75335
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75336
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75337
+ instantiatedType;
75338
+ // Inferences made from return types have lower priority than all other inferences.
75339
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75340
+ }
75329
75341
  // Create a type mapper for instantiating generic contextual types using the inferences made
75330
75342
  // from the return type. We need a separate inference pass here because (a) instantiation of
75331
75343
  // the source type uses the outer context's return mapper (which excludes inferences made from
@@ -107250,7 +107262,7 @@ var ts;
107250
107262
  // Though an error in es2020 modules, in node-flavor es2020 modules, we can helpfully transform this to a synthetic `require` call
107251
107263
  // To give easy access to a synchronous `require` in node-flavor esm. We do the transform even in scenarios where we error, but `import.meta.url`
107252
107264
  // is available, just because the output is reasonable for a node-like runtime.
107253
- return ts.getEmitScriptTarget(compilerOptions) >= ts.ModuleKind.ES2020 ? visitImportEqualsDeclaration(node) : undefined;
107265
+ return ts.getEmitModuleKind(compilerOptions) >= ts.ModuleKind.Node16 ? visitImportEqualsDeclaration(node) : undefined;
107254
107266
  case 271 /* ExportAssignment */:
107255
107267
  return visitExportAssignment(node);
107256
107268
  case 272 /* ExportDeclaration */:
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.20220524",
5
+ "version": "4.8.0-dev.20220525",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [