@typescript-deploys/pr-build 5.7.0-pr-60121-9 → 5.7.0-pr-56941-53

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.
Files changed (3) hide show
  1. package/lib/_tsc.js +336 -55
  2. package/lib/typescript.js +337 -56
  3. package/package.json +1 -1
package/lib/typescript.js CHANGED
@@ -2277,7 +2277,7 @@ module.exports = __toCommonJS(typescript_exports);
2277
2277
 
2278
2278
  // src/compiler/corePublic.ts
2279
2279
  var versionMajorMinor = "5.7";
2280
- var version = `${versionMajorMinor}.0-insiders.20241003`;
2280
+ var version = `${versionMajorMinor}.0-insiders.20241007`;
2281
2281
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2282
2282
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2283
2283
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -6530,6 +6530,7 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
6530
6530
  ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
6531
6531
  ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
6532
6532
  ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
6533
+ ObjectFlags3[ObjectFlags3["IsNarrowedType"] = 16777216] = "IsNarrowedType";
6533
6534
  ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
6534
6535
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
6535
6536
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
@@ -10959,7 +10960,7 @@ var Diagnostics = {
10959
10960
  Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations: diag(9021, 1 /* Error */, "Extends_clause_can_t_contain_an_expression_with_isolatedDeclarations_9021", "Extends clause can't contain an expression with --isolatedDeclarations."),
10960
10961
  Inference_from_class_expressions_is_not_supported_with_isolatedDeclarations: diag(9022, 1 /* Error */, "Inference_from_class_expressions_is_not_supported_with_isolatedDeclarations_9022", "Inference from class expressions is not supported with --isolatedDeclarations."),
10961
10962
  Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations_Add_an_explicit_declaration_for_the_properties_assigned_to_this_function: diag(9023, 1 /* Error */, "Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations__9023", "Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function."),
10962
- Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations: diag(9025, 1 /* Error */, "Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_su_9025", "Declaration emit for this parameter requires implicitly adding undefined to it's type. This is not supported with --isolatedDeclarations."),
10963
+ Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_supported_with_isolatedDeclarations: diag(9025, 1 /* Error */, "Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_sup_9025", "Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations."),
10963
10964
  Declaration_emit_for_this_file_requires_preserving_this_import_for_augmentations_This_is_not_supported_with_isolatedDeclarations: diag(9026, 1 /* Error */, "Declaration_emit_for_this_file_requires_preserving_this_import_for_augmentations_This_is_not_support_9026", "Declaration emit for this file requires preserving this import for augmentations. This is not supported with --isolatedDeclarations."),
10964
10965
  Add_a_type_annotation_to_the_variable_0: diag(9027, 1 /* Error */, "Add_a_type_annotation_to_the_variable_0_9027", "Add a type annotation to the variable {0}."),
10965
10966
  Add_a_type_annotation_to_the_parameter_0: diag(9028, 1 /* Error */, "Add_a_type_annotation_to_the_parameter_0_9028", "Add a type annotation to the parameter {0}."),
@@ -18873,12 +18874,12 @@ function canHaveFlowNode(node) {
18873
18874
  case 80 /* Identifier */:
18874
18875
  case 110 /* ThisKeyword */:
18875
18876
  case 108 /* SuperKeyword */:
18876
- case 166 /* QualifiedName */:
18877
- case 236 /* MetaProperty */:
18878
18877
  case 212 /* ElementAccessExpression */:
18879
18878
  case 211 /* PropertyAccessExpression */:
18880
- case 208 /* BindingElement */:
18881
18879
  case 218 /* FunctionExpression */:
18880
+ case 166 /* QualifiedName */:
18881
+ case 236 /* MetaProperty */:
18882
+ case 208 /* BindingElement */:
18882
18883
  case 219 /* ArrowFunction */:
18883
18884
  case 174 /* MethodDeclaration */:
18884
18885
  case 177 /* GetAccessor */:
@@ -46375,6 +46376,7 @@ function createBinder() {
46375
46376
  var preSwitchCaseFlow;
46376
46377
  var activeLabelList;
46377
46378
  var hasExplicitReturn;
46379
+ var inReturnStatement;
46378
46380
  var hasFlowEffects;
46379
46381
  var emitFlags;
46380
46382
  var inStrictMode;
@@ -46447,6 +46449,7 @@ function createBinder() {
46447
46449
  currentExceptionTarget = void 0;
46448
46450
  activeLabelList = void 0;
46449
46451
  hasExplicitReturn = false;
46452
+ inReturnStatement = false;
46450
46453
  hasFlowEffects = false;
46451
46454
  inAssignmentPattern = false;
46452
46455
  emitFlags = 0 /* None */;
@@ -47211,7 +47214,10 @@ function createBinder() {
47211
47214
  currentFlow = finishFlowLabel(postIfLabel);
47212
47215
  }
47213
47216
  function bindReturnOrThrow(node) {
47217
+ const oldInReturnStatement = inReturnStatement;
47218
+ inReturnStatement = true;
47214
47219
  bind(node.expression);
47220
+ inReturnStatement = oldInReturnStatement;
47215
47221
  if (node.kind === 253 /* ReturnStatement */) {
47216
47222
  hasExplicitReturn = true;
47217
47223
  if (currentReturnTarget) {
@@ -47572,10 +47578,16 @@ function createBinder() {
47572
47578
  hasFlowEffects = false;
47573
47579
  bindCondition(node.condition, trueLabel, falseLabel);
47574
47580
  currentFlow = finishFlowLabel(trueLabel);
47581
+ if (inReturnStatement) {
47582
+ node.flowNodeWhenTrue = currentFlow;
47583
+ }
47575
47584
  bind(node.questionToken);
47576
47585
  bind(node.whenTrue);
47577
47586
  addAntecedent(postExpressionLabel, currentFlow);
47578
47587
  currentFlow = finishFlowLabel(falseLabel);
47588
+ if (inReturnStatement) {
47589
+ node.flowNodeWhenFalse = currentFlow;
47590
+ }
47579
47591
  bind(node.colonToken);
47580
47592
  bind(node.whenFalse);
47581
47593
  addAntecedent(postExpressionLabel, currentFlow);
@@ -51518,6 +51530,7 @@ function createTypeChecker(host) {
51518
51530
  [".jsx", ".jsx"],
51519
51531
  [".json", ".json"]
51520
51532
  ];
51533
+ var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
51521
51534
  initializeTypeChecker();
51522
51535
  return checker;
51523
51536
  function isDefinitelyReferenceToGlobalSymbolObject(node) {
@@ -63747,11 +63760,14 @@ function createTypeChecker(host) {
63747
63760
  function isNoInferType(type) {
63748
63761
  return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
63749
63762
  }
63750
- function getSubstitutionType(baseType, constraint) {
63751
- return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint);
63763
+ function isNarrowingSubstitutionType(type) {
63764
+ return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowedType */);
63765
+ }
63766
+ function getSubstitutionType(baseType, constraint, isNarrowed) {
63767
+ return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
63752
63768
  }
63753
- function getOrCreateSubstitutionType(baseType, constraint) {
63754
- const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
63769
+ function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
63770
+ const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
63755
63771
  const cached = substitutionTypes.get(id);
63756
63772
  if (cached) {
63757
63773
  return cached;
@@ -63759,6 +63775,9 @@ function createTypeChecker(host) {
63759
63775
  const result = createType(33554432 /* Substitution */);
63760
63776
  result.baseType = baseType;
63761
63777
  result.constraint = constraint;
63778
+ if (isNarrowed) {
63779
+ result.objectFlags |= 16777216 /* IsNarrowedType */;
63780
+ }
63762
63781
  substitutionTypes.set(id, result);
63763
63782
  return result;
63764
63783
  }
@@ -65961,7 +65980,7 @@ function createTypeChecker(host) {
65961
65980
  function isDeferredType(type, checkTuples) {
65962
65981
  return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
65963
65982
  }
65964
- function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
65983
+ function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
65965
65984
  let result;
65966
65985
  let extraTypes;
65967
65986
  let tailCount = 0;
@@ -65978,10 +65997,11 @@ function createTypeChecker(host) {
65978
65997
  if (checkType === wildcardType || extendsType === wildcardType) {
65979
65998
  return wildcardType;
65980
65999
  }
66000
+ const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
65981
66001
  const checkTypeNode = skipTypeParentheses(root.node.checkType);
65982
66002
  const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
65983
66003
  const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
65984
- const checkTypeDeferred = isDeferredType(checkType, checkTuples);
66004
+ const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
65985
66005
  let combinedMapper;
65986
66006
  if (root.inferTypeParameters) {
65987
66007
  const context = createInferenceContext(
@@ -66000,8 +66020,8 @@ function createTypeChecker(host) {
66000
66020
  }
66001
66021
  const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
66002
66022
  if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
66003
- if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (checkType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
66004
- if (checkType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(checkType)))) {
66023
+ if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
66024
+ if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
66005
66025
  (extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
66006
66026
  }
66007
66027
  const falseType2 = getTypeFromTypeNode(root.node.falseType);
@@ -66018,7 +66038,7 @@ function createTypeChecker(host) {
66018
66038
  result = instantiateType(falseType2, mapper);
66019
66039
  break;
66020
66040
  }
66021
- if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
66041
+ if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
66022
66042
  const trueType2 = getTypeFromTypeNode(root.node.trueType);
66023
66043
  const trueMapper = combinedMapper || mapper;
66024
66044
  if (canTailRecurse(trueType2, trueMapper)) {
@@ -66984,8 +67004,44 @@ function createTypeChecker(host) {
66984
67004
  if (!result) {
66985
67005
  const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
66986
67006
  const checkType = root.checkType;
66987
- const distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
66988
- result = distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments) : getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments);
67007
+ let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
67008
+ let narrowingBaseType;
67009
+ const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
67010
+ if (forNarrowing) {
67011
+ narrowingBaseType = distributionType.baseType;
67012
+ distributionType = getReducedType(distributionType.constraint);
67013
+ }
67014
+ if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
67015
+ const mapperCallback = narrowingBaseType ? (t) => getConditionalType(
67016
+ root,
67017
+ prependTypeMapping(checkType, getSubstitutionType(
67018
+ narrowingBaseType,
67019
+ t,
67020
+ /*isNarrowed*/
67021
+ true
67022
+ ), newMapper),
67023
+ forConstraint,
67024
+ /*aliasSymbol*/
67025
+ void 0,
67026
+ /*aliasTypeArguments*/
67027
+ void 0,
67028
+ forNarrowing
67029
+ ) : (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint);
67030
+ if (narrowingBaseType) {
67031
+ result = mapType(
67032
+ distributionType,
67033
+ mapperCallback,
67034
+ /*noReductions*/
67035
+ void 0,
67036
+ /*toIntersection*/
67037
+ true
67038
+ );
67039
+ } else {
67040
+ result = mapTypeWithAlias(distributionType, mapperCallback, aliasSymbol, aliasTypeArguments);
67041
+ }
67042
+ } else {
67043
+ result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
67044
+ }
66989
67045
  root.instantiations.set(id, result);
66990
67046
  }
66991
67047
  return result;
@@ -67098,6 +67154,9 @@ function createTypeChecker(host) {
67098
67154
  }
67099
67155
  return type;
67100
67156
  }
67157
+ function isGenericIndexedOrConditionalReturnType(type) {
67158
+ return !!(type.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */) && couldContainTypeVariables(type));
67159
+ }
67101
67160
  function instantiateReverseMappedType(type, mapper) {
67102
67161
  const innerMappedType = instantiateType(type.mappedType, mapper);
67103
67162
  if (!(getObjectFlags(innerMappedType) & 32 /* Mapped */)) {
@@ -68128,10 +68187,12 @@ function createTypeChecker(host) {
68128
68187
  function shouldNormalizeIntersection(type) {
68129
68188
  let hasInstantiable = false;
68130
68189
  let hasNullableOrEmpty = false;
68190
+ let hasSubstitution = false;
68131
68191
  for (const t of type.types) {
68132
68192
  hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
68133
68193
  hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
68134
- if (hasInstantiable && hasNullableOrEmpty) return true;
68194
+ hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
68195
+ if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
68135
68196
  }
68136
68197
  return false;
68137
68198
  }
@@ -73266,7 +73327,7 @@ function createTypeChecker(host) {
73266
73327
  function countTypes(type) {
73267
73328
  return type.flags & 1048576 /* Union */ ? type.types.length : 1;
73268
73329
  }
73269
- function mapType(type, mapper, noReductions) {
73330
+ function mapType(type, mapper, noReductions, toIntersection) {
73270
73331
  if (type.flags & 131072 /* Never */) {
73271
73332
  return type;
73272
73333
  }
@@ -73288,7 +73349,7 @@ function createTypeChecker(host) {
73288
73349
  }
73289
73350
  }
73290
73351
  }
73291
- return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
73352
+ return changed ? mappedTypes && (toIntersection ? getIntersectionType(mappedTypes) : getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */)) : type;
73292
73353
  }
73293
73354
  function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
73294
73355
  return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
@@ -74641,14 +74702,12 @@ function createTypeChecker(host) {
74641
74702
  case 80 /* Identifier */:
74642
74703
  if (!isMatchingReference(reference, expr) && inlineLevel < 5) {
74643
74704
  const symbol = getResolvedSymbol(expr);
74644
- if (isConstantVariable(symbol)) {
74645
- const declaration = symbol.valueDeclaration;
74646
- if (declaration && isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && isConstantReference(reference)) {
74647
- inlineLevel++;
74648
- const result = narrowType(type, declaration.initializer, assumeTrue);
74649
- inlineLevel--;
74650
- return result;
74651
- }
74705
+ const inlineExpression = getNarrowableInlineExpression(symbol);
74706
+ if (inlineExpression && isConstantReference(reference)) {
74707
+ inlineLevel++;
74708
+ const result = narrowType(type, inlineExpression, assumeTrue);
74709
+ inlineLevel--;
74710
+ return result;
74652
74711
  }
74653
74712
  }
74654
74713
  // falls through
@@ -74683,6 +74742,14 @@ function createTypeChecker(host) {
74683
74742
  return type;
74684
74743
  }
74685
74744
  }
74745
+ function getNarrowableInlineExpression(symbol) {
74746
+ if (isConstantVariable(symbol)) {
74747
+ const declaration = symbol.valueDeclaration;
74748
+ if (declaration && isVariableDeclaration(declaration) && !declaration.type && declaration.initializer) {
74749
+ return declaration.initializer;
74750
+ }
74751
+ }
74752
+ }
74686
74753
  function getTypeOfSymbolAtLocation(symbol, location) {
74687
74754
  symbol = getExportSymbolOfValueSymbolIfExported(symbol);
74688
74755
  if (location.kind === 80 /* Identifier */ || location.kind === 81 /* PrivateIdentifier */) {
@@ -74872,11 +74939,11 @@ function createTypeChecker(host) {
74872
74939
  ));
74873
74940
  return contextualType && !isGenericType(contextualType);
74874
74941
  }
74875
- function getNarrowableTypeForReference(type, reference, checkMode) {
74942
+ function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
74876
74943
  if (isNoInferType(type)) {
74877
74944
  type = type.baseType;
74878
74945
  }
74879
- const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
74946
+ const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
74880
74947
  return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
74881
74948
  }
74882
74949
  function isExportOrExportExpression(location) {
@@ -75029,7 +75096,7 @@ function createTypeChecker(host) {
75029
75096
  jsxFactorySym = resolveName(
75030
75097
  jsxFactoryLocation,
75031
75098
  jsxFactoryNamespace,
75032
- 111551 /* Value */,
75099
+ compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
75033
75100
  jsxFactoryRefErr,
75034
75101
  /*isUse*/
75035
75102
  true
@@ -75048,7 +75115,7 @@ function createTypeChecker(host) {
75048
75115
  resolveName(
75049
75116
  jsxFactoryLocation,
75050
75117
  localJsxNamespace,
75051
- 111551 /* Value */,
75118
+ compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
75052
75119
  jsxFactoryRefErr,
75053
75120
  /*isUse*/
75054
75121
  true
@@ -76001,9 +76068,16 @@ function createTypeChecker(host) {
76001
76068
  function getContextualTypeForReturnExpression(node, contextFlags) {
76002
76069
  const func = getContainingFunction(node);
76003
76070
  if (func) {
76071
+ const functionFlags = getFunctionFlags(func);
76072
+ const links = getNodeLinks(node);
76073
+ if (links.contextualReturnType) {
76074
+ if (functionFlags & 2 /* Async */) {
76075
+ return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
76076
+ }
76077
+ return links.contextualReturnType;
76078
+ }
76004
76079
  let contextualReturnType = getContextualReturnType(func, contextFlags);
76005
76080
  if (contextualReturnType) {
76006
- const functionFlags = getFunctionFlags(func);
76007
76081
  if (functionFlags & 1 /* Generator */) {
76008
76082
  const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
76009
76083
  if (contextualReturnType.flags & 1048576 /* Union */) {
@@ -76701,6 +76775,13 @@ function createTypeChecker(host) {
76701
76775
  if (index >= 0) {
76702
76776
  return contextualTypes[index];
76703
76777
  }
76778
+ const links = getNodeLinks(node);
76779
+ if (links.contextualReturnType) {
76780
+ if (node.flags & 65536 /* AwaitContext */) {
76781
+ return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
76782
+ }
76783
+ return links.contextualReturnType;
76784
+ }
76704
76785
  const { parent: parent2 } = node;
76705
76786
  switch (parent2.kind) {
76706
76787
  case 260 /* VariableDeclaration */:
@@ -77506,7 +77587,8 @@ function createTypeChecker(host) {
77506
77587
  );
77507
77588
  }
77508
77589
  checkJsxChildren(node);
77509
- return getJsxElementTypeAt(node) || anyType;
77590
+ const jsxElementType = getJsxElementTypeAt(node);
77591
+ return isErrorType(jsxElementType) ? anyType : jsxElementType;
77510
77592
  }
77511
77593
  function isHyphenatedJsxName(name) {
77512
77594
  return name.includes("-");
@@ -80566,11 +80648,12 @@ function createTypeChecker(host) {
80566
80648
  const sourceFileLinks = getNodeLinks(getSourceFileOfNode(node));
80567
80649
  if (sourceFileLinks.jsxFragmentType !== void 0) return sourceFileLinks.jsxFragmentType;
80568
80650
  const jsxFragmentFactoryName = getJsxNamespace(node);
80651
+ if (jsxFragmentFactoryName === "null") return sourceFileLinks.jsxFragmentType = anyType;
80569
80652
  const jsxFactoryRefErr = diagnostics ? Diagnostics.Using_JSX_fragments_requires_fragment_factory_0_to_be_in_scope_but_it_could_not_be_found : void 0;
80570
80653
  const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ?? resolveName(
80571
80654
  node,
80572
80655
  jsxFragmentFactoryName,
80573
- 111551 /* Value */,
80656
+ compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
80574
80657
  /*nameNotFoundMessage*/
80575
80658
  jsxFactoryRefErr,
80576
80659
  /*isUse*/
@@ -86505,11 +86588,8 @@ function createTypeChecker(host) {
86505
86588
  }
86506
86589
  const parent2 = node.parent.parent;
86507
86590
  const parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
86591
+ const parentType = getTypeForBindingElementParent(parent2, parentCheckMode);
86508
86592
  const name = node.propertyName || node.name;
86509
- let parentType = getTypeForBindingElementParent(parent2, parentCheckMode);
86510
- if (parentType && !parent2.initializer) {
86511
- parentType = checkNonNullType(parentType, parent2);
86512
- }
86513
86593
  if (parentType && !isBindingPattern(name)) {
86514
86594
  const exprType = getLiteralTypeFromPropertyName(name);
86515
86595
  if (isTypeUsableAsPropertyName(exprType)) {
@@ -86549,15 +86629,16 @@ function createTypeChecker(host) {
86549
86629
  if (isInAmbientOrTypeNode(node)) {
86550
86630
  return;
86551
86631
  }
86552
- const needCheckInitializer = node.initializer && node.parent.parent.kind !== 249 /* ForInStatement */;
86632
+ const needCheckInitializer = hasOnlyExpressionInitializer(node) && node.initializer && node.parent.parent.kind !== 249 /* ForInStatement */;
86553
86633
  const needCheckWidenedType = !some(node.name.elements, not(isOmittedExpression));
86554
86634
  if (needCheckInitializer || needCheckWidenedType) {
86555
86635
  const widenedType = getWidenedTypeForVariableLikeDeclaration(node);
86556
86636
  if (needCheckInitializer) {
86637
+ const initializerType = checkExpressionCached(node.initializer);
86557
86638
  if (strictNullChecks && needCheckWidenedType) {
86558
- checkNonNullNonVoidType(checkExpressionCached(node.initializer), node);
86639
+ checkNonNullNonVoidType(initializerType, node);
86559
86640
  } else {
86560
- checkTypeAssignableToAndOptionallyElaborate(checkNonNullExpression(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, node.initializer);
86641
+ checkTypeAssignableToAndOptionallyElaborate(initializerType, getWidenedTypeForVariableLikeDeclaration(node), node, node.initializer);
86561
86642
  }
86562
86643
  }
86563
86644
  if (needCheckWidenedType) {
@@ -87590,34 +87671,234 @@ function createTypeChecker(host) {
87590
87671
  }
87591
87672
  const signature = getSignatureFromDeclaration(container);
87592
87673
  const returnType = getReturnTypeOfSignature(signature);
87593
- const functionFlags = getFunctionFlags(container);
87594
87674
  if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
87595
- const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
87596
87675
  if (container.kind === 178 /* SetAccessor */) {
87597
87676
  if (node.expression) {
87598
87677
  error2(node, Diagnostics.Setters_cannot_return_a_value);
87599
87678
  }
87600
87679
  } else if (container.kind === 176 /* Constructor */) {
87680
+ const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
87601
87681
  if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType, returnType, node, node.expression)) {
87602
87682
  error2(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
87603
87683
  }
87604
87684
  } else if (getReturnTypeFromAnnotation(container)) {
87605
- const unwrappedReturnType = unwrapReturnType(returnType, functionFlags) ?? returnType;
87606
- const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
87607
- exprType,
87608
- /*withAlias*/
87609
- false,
87610
- node,
87611
- Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
87612
- ) : exprType;
87613
- if (unwrappedReturnType) {
87614
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, node, node.expression);
87615
- }
87685
+ checkReturnStatementExpression(container, returnType, node, node.expression);
87616
87686
  }
87617
87687
  } else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
87618
87688
  error2(node, Diagnostics.Not_all_code_paths_return_a_value);
87619
87689
  }
87620
87690
  }
87691
+ function checkReturnStatementExpression(container, returnType, node, expr) {
87692
+ const functionFlags = getFunctionFlags(container);
87693
+ const unwrappedReturnType = unwrapReturnType(returnType, functionFlags) ?? returnType;
87694
+ if (expr) {
87695
+ const unwrappedExpr = skipParentheses(expr);
87696
+ if (isConditionalExpression(unwrappedExpr)) {
87697
+ return checkReturnConditionalExpression(container, returnType, node, unwrappedExpr);
87698
+ }
87699
+ }
87700
+ const exprType = expr ? checkExpressionCached(expr) : undefinedType;
87701
+ const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
87702
+ exprType,
87703
+ /*withAlias*/
87704
+ false,
87705
+ node,
87706
+ Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
87707
+ ) : exprType;
87708
+ const errorNode = node.expression && isConditionalExpression(skipParentheses(node.expression)) ? expr : node;
87709
+ if (checkTypeAssignableTo(
87710
+ unwrappedExprType,
87711
+ unwrappedReturnType,
87712
+ /*errorNode*/
87713
+ void 0
87714
+ )) {
87715
+ return;
87716
+ }
87717
+ if (!isGenericIndexedOrConditionalReturnType(unwrappedReturnType)) {
87718
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, expr);
87719
+ return;
87720
+ }
87721
+ const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
87722
+ container,
87723
+ /*includeThisTypes*/
87724
+ false
87725
+ ), getEffectiveTypeParameterDeclarations(container));
87726
+ const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
87727
+ if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
87728
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, expr);
87729
+ return;
87730
+ }
87731
+ let narrowPosition = node;
87732
+ let narrowFlowNode = node.flowNode;
87733
+ if (expr && isConditionalExpression(expr.parent)) {
87734
+ narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
87735
+ narrowPosition = expr;
87736
+ }
87737
+ if (!narrowFlowNode) {
87738
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, expr);
87739
+ return;
87740
+ }
87741
+ const narrowed = mapDefined(narrowableTypeParameters, ([typeParam, symbol, reference]) => {
87742
+ const narrowReference = factory.cloneNode(reference);
87743
+ narrowReference.id = void 0;
87744
+ getNodeLinks(narrowReference).resolvedSymbol = symbol;
87745
+ setParent(narrowReference, narrowPosition.parent);
87746
+ narrowReference.flowNode = narrowFlowNode;
87747
+ const initialType = getNarrowableTypeForReference(
87748
+ typeParam,
87749
+ narrowReference,
87750
+ /*checkMode*/
87751
+ void 0,
87752
+ /*forReturnTypeNarrowing*/
87753
+ true
87754
+ );
87755
+ if (initialType === typeParam) {
87756
+ return void 0;
87757
+ }
87758
+ const flowType = getFlowTypeOfReference(narrowReference, initialType);
87759
+ const exprType2 = getTypeFromFlowType(flowType);
87760
+ if (isTypeAny(exprType2) || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
87761
+ return void 0;
87762
+ }
87763
+ const narrowedType = getSubstitutionType(
87764
+ typeParam,
87765
+ exprType2,
87766
+ /*isNarrowed*/
87767
+ true
87768
+ );
87769
+ return [typeParam, narrowedType];
87770
+ });
87771
+ const narrowMapper = createTypeMapper(narrowed.map(([tp, _]) => tp), narrowed.map(([_, t]) => t));
87772
+ const narrowedReturnType = instantiateType(
87773
+ unwrappedReturnType,
87774
+ narrowMapper
87775
+ );
87776
+ if (expr) {
87777
+ const links = getNodeLinks(expr);
87778
+ if (!links.contextualReturnType) {
87779
+ links.contextualReturnType = narrowedReturnType;
87780
+ }
87781
+ }
87782
+ const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
87783
+ const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
87784
+ narrowedExprType,
87785
+ /*withAlias*/
87786
+ false,
87787
+ node,
87788
+ Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
87789
+ ) : narrowedExprType;
87790
+ checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, expr);
87791
+ }
87792
+ function checkReturnConditionalExpression(container, returnType, node, expr) {
87793
+ checkExpression(expr.condition);
87794
+ checkReturnStatementExpression(container, returnType, node, expr.whenTrue);
87795
+ checkReturnStatementExpression(container, returnType, node, expr.whenFalse);
87796
+ }
87797
+ function getNarrowableTypeParameters(candidates) {
87798
+ const narrowableParams = [];
87799
+ for (const typeParam of candidates) {
87800
+ const constraint = getConstraintOfTypeParameter(typeParam);
87801
+ if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
87802
+ if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
87803
+ const container = typeParam.symbol.declarations[0].parent;
87804
+ if (!isFunctionLike(container)) continue;
87805
+ let reference;
87806
+ let hasInvalidReference = false;
87807
+ for (const paramDecl of container.parameters) {
87808
+ const typeNode = paramDecl.type;
87809
+ if (!typeNode) continue;
87810
+ if (isTypeParameterReferenced(typeParam, typeNode)) {
87811
+ let candidateReference;
87812
+ if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
87813
+ if (reference) {
87814
+ hasInvalidReference = true;
87815
+ break;
87816
+ }
87817
+ reference = candidateReference;
87818
+ continue;
87819
+ }
87820
+ hasInvalidReference = true;
87821
+ break;
87822
+ }
87823
+ }
87824
+ if (!hasInvalidReference && reference) {
87825
+ const symbol = getResolvedSymbol(reference);
87826
+ if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
87827
+ }
87828
+ }
87829
+ }
87830
+ return narrowableParams;
87831
+ function getValidParameterReference(paramDecl, constraint) {
87832
+ if (!isIdentifier(paramDecl.name)) return;
87833
+ if (paramDecl.questionToken && !containsUndefinedType(constraint)) return;
87834
+ return paramDecl.name;
87835
+ }
87836
+ function isReferenceToTypeParameter(typeParam, node) {
87837
+ return getTypeFromTypeReference(node) === typeParam;
87838
+ }
87839
+ function isTypeParameterReferenced(typeParam, node) {
87840
+ return isReferenced(node);
87841
+ function isReferenced(node2) {
87842
+ if (isTypeReferenceNode(node2)) {
87843
+ return isReferenceToTypeParameter(typeParam, node2);
87844
+ }
87845
+ if (isTypeQueryNode(node2)) {
87846
+ return isTypeParameterPossiblyReferenced(typeParam, node2);
87847
+ }
87848
+ return !!forEachChild(node2, isReferenced);
87849
+ }
87850
+ }
87851
+ }
87852
+ function isNarrowableReturnType(returnType) {
87853
+ return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
87854
+ }
87855
+ function isNarrowableConditionalType(type, mapper) {
87856
+ const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
87857
+ const mapped = getMappedType(t, mapper);
87858
+ if (isNarrowingSubstitutionType(mapped)) {
87859
+ return mapped.baseType;
87860
+ }
87861
+ return mapped;
87862
+ });
87863
+ const id = `${type.id}:${getTypeListId(typeArguments)}`;
87864
+ let result = narrowableReturnTypeCache.get(id);
87865
+ if (result === void 0) {
87866
+ const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
87867
+ const instantiatedType = instantiateType(type, nonNarrowingMapper);
87868
+ result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
87869
+ narrowableReturnTypeCache.set(id, result);
87870
+ }
87871
+ return result;
87872
+ }
87873
+ function isNarrowableConditionalTypeWorker(type) {
87874
+ if (!type.root.isDistributive) {
87875
+ return false;
87876
+ }
87877
+ if (type.root.inferTypeParameters) {
87878
+ return false;
87879
+ }
87880
+ if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
87881
+ return false;
87882
+ }
87883
+ const constraintType = getConstraintOfTypeParameter(type.checkType);
87884
+ if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
87885
+ return false;
87886
+ }
87887
+ if (!everyType(type.extendsType, (extendsType) => some(
87888
+ constraintType.types,
87889
+ (constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
87890
+ ))) {
87891
+ return false;
87892
+ }
87893
+ const trueType2 = getTrueTypeFromConditionalType(type);
87894
+ const falseType2 = getFalseTypeFromConditionalType(type);
87895
+ const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
87896
+ const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
87897
+ return isValidTrueType && isValidFalseType;
87898
+ }
87899
+ function isConditionalType(type) {
87900
+ return !!(type.flags & 16777216 /* Conditional */);
87901
+ }
87621
87902
  function checkWithStatement(node) {
87622
87903
  if (!checkGrammarStatementInAmbientContext(node)) {
87623
87904
  if (node.flags & 65536 /* AwaitContext */) {
@@ -116917,7 +117198,7 @@ function createGetIsolatedDeclarationErrors(resolver) {
116917
117198
  if (!addUndefined && node.initializer) {
116918
117199
  return createExpressionError(node.initializer);
116919
117200
  }
116920
- const message = addUndefined ? Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations : errorByDeclarationKind[node.kind];
117201
+ const message = addUndefined ? Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_supported_with_isolatedDeclarations : errorByDeclarationKind[node.kind];
116921
117202
  const diag2 = createDiagnosticForNode(node, message);
116922
117203
  const targetStr = getTextOfNode(
116923
117204
  node.name,
@@ -161194,7 +161475,7 @@ var errorCodes48 = [
161194
161475
  Diagnostics.Default_exports_can_t_be_inferred_with_isolatedDeclarations.code,
161195
161476
  Diagnostics.Only_const_arrays_can_be_inferred_with_isolatedDeclarations.code,
161196
161477
  Diagnostics.Assigning_properties_to_functions_without_declaring_them_is_not_supported_with_isolatedDeclarations_Add_an_explicit_declaration_for_the_properties_assigned_to_this_function.code,
161197
- Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_it_s_type_This_is_not_supported_with_isolatedDeclarations.code,
161478
+ Diagnostics.Declaration_emit_for_this_parameter_requires_implicitly_adding_undefined_to_its_type_This_is_not_supported_with_isolatedDeclarations.code,
161198
161479
  Diagnostics.Type_containing_private_name_0_can_t_be_used_with_isolatedDeclarations.code,
161199
161480
  Diagnostics.Add_satisfies_and_a_type_assertion_to_this_expression_satisfies_T_as_T_to_make_the_type_explicit.code
161200
161481
  ];