@typescript-deploys/pr-build 5.7.0-pr-60122-16 → 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.
- package/lib/_tsc.js +325 -44
- package/lib/typescript.js +326 -45
- package/package.json +1 -1
package/lib/_tsc.js
CHANGED
|
@@ -18,7 +18,7 @@ and limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
// src/compiler/corePublic.ts
|
|
20
20
|
var versionMajorMinor = "5.7";
|
|
21
|
-
var version = `${versionMajorMinor}.0-insiders.
|
|
21
|
+
var version = `${versionMajorMinor}.0-insiders.20241007`;
|
|
22
22
|
|
|
23
23
|
// src/compiler/core.ts
|
|
24
24
|
var emptyArray = [];
|
|
@@ -3680,6 +3680,7 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
|
|
|
3680
3680
|
ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
|
|
3681
3681
|
ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
|
|
3682
3682
|
ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
|
|
3683
|
+
ObjectFlags3[ObjectFlags3["IsNarrowedType"] = 16777216] = "IsNarrowedType";
|
|
3683
3684
|
ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
|
|
3684
3685
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
|
|
3685
3686
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
|
|
@@ -7582,7 +7583,7 @@ var Diagnostics = {
|
|
|
7582
7583
|
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."),
|
|
7583
7584
|
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."),
|
|
7584
7585
|
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."),
|
|
7585
|
-
|
|
7586
|
+
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."),
|
|
7586
7587
|
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."),
|
|
7587
7588
|
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}."),
|
|
7588
7589
|
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}."),
|
|
@@ -15157,12 +15158,12 @@ function canHaveFlowNode(node) {
|
|
|
15157
15158
|
case 80 /* Identifier */:
|
|
15158
15159
|
case 110 /* ThisKeyword */:
|
|
15159
15160
|
case 108 /* SuperKeyword */:
|
|
15160
|
-
case 166 /* QualifiedName */:
|
|
15161
|
-
case 236 /* MetaProperty */:
|
|
15162
15161
|
case 212 /* ElementAccessExpression */:
|
|
15163
15162
|
case 211 /* PropertyAccessExpression */:
|
|
15164
|
-
case 208 /* BindingElement */:
|
|
15165
15163
|
case 218 /* FunctionExpression */:
|
|
15164
|
+
case 166 /* QualifiedName */:
|
|
15165
|
+
case 236 /* MetaProperty */:
|
|
15166
|
+
case 208 /* BindingElement */:
|
|
15166
15167
|
case 219 /* ArrowFunction */:
|
|
15167
15168
|
case 174 /* MethodDeclaration */:
|
|
15168
15169
|
case 177 /* GetAccessor */:
|
|
@@ -41872,6 +41873,7 @@ function createBinder() {
|
|
|
41872
41873
|
var preSwitchCaseFlow;
|
|
41873
41874
|
var activeLabelList;
|
|
41874
41875
|
var hasExplicitReturn;
|
|
41876
|
+
var inReturnStatement;
|
|
41875
41877
|
var hasFlowEffects;
|
|
41876
41878
|
var emitFlags;
|
|
41877
41879
|
var inStrictMode;
|
|
@@ -41944,6 +41946,7 @@ function createBinder() {
|
|
|
41944
41946
|
currentExceptionTarget = void 0;
|
|
41945
41947
|
activeLabelList = void 0;
|
|
41946
41948
|
hasExplicitReturn = false;
|
|
41949
|
+
inReturnStatement = false;
|
|
41947
41950
|
hasFlowEffects = false;
|
|
41948
41951
|
inAssignmentPattern = false;
|
|
41949
41952
|
emitFlags = 0 /* None */;
|
|
@@ -42708,7 +42711,10 @@ function createBinder() {
|
|
|
42708
42711
|
currentFlow = finishFlowLabel(postIfLabel);
|
|
42709
42712
|
}
|
|
42710
42713
|
function bindReturnOrThrow(node) {
|
|
42714
|
+
const oldInReturnStatement = inReturnStatement;
|
|
42715
|
+
inReturnStatement = true;
|
|
42711
42716
|
bind(node.expression);
|
|
42717
|
+
inReturnStatement = oldInReturnStatement;
|
|
42712
42718
|
if (node.kind === 253 /* ReturnStatement */) {
|
|
42713
42719
|
hasExplicitReturn = true;
|
|
42714
42720
|
if (currentReturnTarget) {
|
|
@@ -43069,10 +43075,16 @@ function createBinder() {
|
|
|
43069
43075
|
hasFlowEffects = false;
|
|
43070
43076
|
bindCondition(node.condition, trueLabel, falseLabel);
|
|
43071
43077
|
currentFlow = finishFlowLabel(trueLabel);
|
|
43078
|
+
if (inReturnStatement) {
|
|
43079
|
+
node.flowNodeWhenTrue = currentFlow;
|
|
43080
|
+
}
|
|
43072
43081
|
bind(node.questionToken);
|
|
43073
43082
|
bind(node.whenTrue);
|
|
43074
43083
|
addAntecedent(postExpressionLabel, currentFlow);
|
|
43075
43084
|
currentFlow = finishFlowLabel(falseLabel);
|
|
43085
|
+
if (inReturnStatement) {
|
|
43086
|
+
node.flowNodeWhenFalse = currentFlow;
|
|
43087
|
+
}
|
|
43076
43088
|
bind(node.colonToken);
|
|
43077
43089
|
bind(node.whenFalse);
|
|
43078
43090
|
addAntecedent(postExpressionLabel, currentFlow);
|
|
@@ -46915,6 +46927,7 @@ function createTypeChecker(host) {
|
|
|
46915
46927
|
[".jsx", ".jsx"],
|
|
46916
46928
|
[".json", ".json"]
|
|
46917
46929
|
];
|
|
46930
|
+
var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
|
|
46918
46931
|
initializeTypeChecker();
|
|
46919
46932
|
return checker;
|
|
46920
46933
|
function isDefinitelyReferenceToGlobalSymbolObject(node) {
|
|
@@ -59144,11 +59157,14 @@ function createTypeChecker(host) {
|
|
|
59144
59157
|
function isNoInferType(type) {
|
|
59145
59158
|
return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
|
|
59146
59159
|
}
|
|
59147
|
-
function
|
|
59148
|
-
return
|
|
59160
|
+
function isNarrowingSubstitutionType(type) {
|
|
59161
|
+
return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowedType */);
|
|
59149
59162
|
}
|
|
59150
|
-
function
|
|
59151
|
-
|
|
59163
|
+
function getSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59164
|
+
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
|
|
59165
|
+
}
|
|
59166
|
+
function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59167
|
+
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
|
|
59152
59168
|
const cached = substitutionTypes.get(id);
|
|
59153
59169
|
if (cached) {
|
|
59154
59170
|
return cached;
|
|
@@ -59156,6 +59172,9 @@ function createTypeChecker(host) {
|
|
|
59156
59172
|
const result = createType(33554432 /* Substitution */);
|
|
59157
59173
|
result.baseType = baseType;
|
|
59158
59174
|
result.constraint = constraint;
|
|
59175
|
+
if (isNarrowed) {
|
|
59176
|
+
result.objectFlags |= 16777216 /* IsNarrowedType */;
|
|
59177
|
+
}
|
|
59159
59178
|
substitutionTypes.set(id, result);
|
|
59160
59179
|
return result;
|
|
59161
59180
|
}
|
|
@@ -61358,7 +61377,7 @@ function createTypeChecker(host) {
|
|
|
61358
61377
|
function isDeferredType(type, checkTuples) {
|
|
61359
61378
|
return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
|
|
61360
61379
|
}
|
|
61361
|
-
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
|
|
61380
|
+
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
|
|
61362
61381
|
let result;
|
|
61363
61382
|
let extraTypes;
|
|
61364
61383
|
let tailCount = 0;
|
|
@@ -61375,10 +61394,11 @@ function createTypeChecker(host) {
|
|
|
61375
61394
|
if (checkType === wildcardType || extendsType === wildcardType) {
|
|
61376
61395
|
return wildcardType;
|
|
61377
61396
|
}
|
|
61397
|
+
const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
|
|
61378
61398
|
const checkTypeNode = skipTypeParentheses(root.node.checkType);
|
|
61379
61399
|
const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
|
|
61380
61400
|
const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
|
|
61381
|
-
const checkTypeDeferred = isDeferredType(
|
|
61401
|
+
const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
|
|
61382
61402
|
let combinedMapper;
|
|
61383
61403
|
if (root.inferTypeParameters) {
|
|
61384
61404
|
const context = createInferenceContext(
|
|
@@ -61397,8 +61417,8 @@ function createTypeChecker(host) {
|
|
|
61397
61417
|
}
|
|
61398
61418
|
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
|
|
61399
61419
|
if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
|
|
61400
|
-
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (
|
|
61401
|
-
if (
|
|
61420
|
+
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
|
|
61421
|
+
if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
|
|
61402
61422
|
(extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
|
|
61403
61423
|
}
|
|
61404
61424
|
const falseType2 = getTypeFromTypeNode(root.node.falseType);
|
|
@@ -61415,7 +61435,7 @@ function createTypeChecker(host) {
|
|
|
61415
61435
|
result = instantiateType(falseType2, mapper);
|
|
61416
61436
|
break;
|
|
61417
61437
|
}
|
|
61418
|
-
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(
|
|
61438
|
+
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
|
|
61419
61439
|
const trueType2 = getTypeFromTypeNode(root.node.trueType);
|
|
61420
61440
|
const trueMapper = combinedMapper || mapper;
|
|
61421
61441
|
if (canTailRecurse(trueType2, trueMapper)) {
|
|
@@ -62381,8 +62401,44 @@ function createTypeChecker(host) {
|
|
|
62381
62401
|
if (!result) {
|
|
62382
62402
|
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
|
|
62383
62403
|
const checkType = root.checkType;
|
|
62384
|
-
|
|
62385
|
-
|
|
62404
|
+
let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
|
|
62405
|
+
let narrowingBaseType;
|
|
62406
|
+
const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
|
|
62407
|
+
if (forNarrowing) {
|
|
62408
|
+
narrowingBaseType = distributionType.baseType;
|
|
62409
|
+
distributionType = getReducedType(distributionType.constraint);
|
|
62410
|
+
}
|
|
62411
|
+
if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
|
|
62412
|
+
const mapperCallback = narrowingBaseType ? (t) => getConditionalType(
|
|
62413
|
+
root,
|
|
62414
|
+
prependTypeMapping(checkType, getSubstitutionType(
|
|
62415
|
+
narrowingBaseType,
|
|
62416
|
+
t,
|
|
62417
|
+
/*isNarrowed*/
|
|
62418
|
+
true
|
|
62419
|
+
), newMapper),
|
|
62420
|
+
forConstraint,
|
|
62421
|
+
/*aliasSymbol*/
|
|
62422
|
+
void 0,
|
|
62423
|
+
/*aliasTypeArguments*/
|
|
62424
|
+
void 0,
|
|
62425
|
+
forNarrowing
|
|
62426
|
+
) : (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint);
|
|
62427
|
+
if (narrowingBaseType) {
|
|
62428
|
+
result = mapType(
|
|
62429
|
+
distributionType,
|
|
62430
|
+
mapperCallback,
|
|
62431
|
+
/*noReductions*/
|
|
62432
|
+
void 0,
|
|
62433
|
+
/*toIntersection*/
|
|
62434
|
+
true
|
|
62435
|
+
);
|
|
62436
|
+
} else {
|
|
62437
|
+
result = mapTypeWithAlias(distributionType, mapperCallback, aliasSymbol, aliasTypeArguments);
|
|
62438
|
+
}
|
|
62439
|
+
} else {
|
|
62440
|
+
result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
|
|
62441
|
+
}
|
|
62386
62442
|
root.instantiations.set(id, result);
|
|
62387
62443
|
}
|
|
62388
62444
|
return result;
|
|
@@ -62495,6 +62551,9 @@ function createTypeChecker(host) {
|
|
|
62495
62551
|
}
|
|
62496
62552
|
return type;
|
|
62497
62553
|
}
|
|
62554
|
+
function isGenericIndexedOrConditionalReturnType(type) {
|
|
62555
|
+
return !!(type.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */) && couldContainTypeVariables(type));
|
|
62556
|
+
}
|
|
62498
62557
|
function instantiateReverseMappedType(type, mapper) {
|
|
62499
62558
|
const innerMappedType = instantiateType(type.mappedType, mapper);
|
|
62500
62559
|
if (!(getObjectFlags(innerMappedType) & 32 /* Mapped */)) {
|
|
@@ -63525,10 +63584,12 @@ function createTypeChecker(host) {
|
|
|
63525
63584
|
function shouldNormalizeIntersection(type) {
|
|
63526
63585
|
let hasInstantiable = false;
|
|
63527
63586
|
let hasNullableOrEmpty = false;
|
|
63587
|
+
let hasSubstitution = false;
|
|
63528
63588
|
for (const t of type.types) {
|
|
63529
63589
|
hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
|
|
63530
63590
|
hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
|
|
63531
|
-
|
|
63591
|
+
hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
|
|
63592
|
+
if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
|
|
63532
63593
|
}
|
|
63533
63594
|
return false;
|
|
63534
63595
|
}
|
|
@@ -68663,7 +68724,7 @@ function createTypeChecker(host) {
|
|
|
68663
68724
|
function countTypes(type) {
|
|
68664
68725
|
return type.flags & 1048576 /* Union */ ? type.types.length : 1;
|
|
68665
68726
|
}
|
|
68666
|
-
function mapType(type, mapper, noReductions) {
|
|
68727
|
+
function mapType(type, mapper, noReductions, toIntersection) {
|
|
68667
68728
|
if (type.flags & 131072 /* Never */) {
|
|
68668
68729
|
return type;
|
|
68669
68730
|
}
|
|
@@ -68685,7 +68746,7 @@ function createTypeChecker(host) {
|
|
|
68685
68746
|
}
|
|
68686
68747
|
}
|
|
68687
68748
|
}
|
|
68688
|
-
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
|
|
68749
|
+
return changed ? mappedTypes && (toIntersection ? getIntersectionType(mappedTypes) : getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */)) : type;
|
|
68689
68750
|
}
|
|
68690
68751
|
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
|
|
68691
68752
|
return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
|
|
@@ -70038,14 +70099,12 @@ function createTypeChecker(host) {
|
|
|
70038
70099
|
case 80 /* Identifier */:
|
|
70039
70100
|
if (!isMatchingReference(reference, expr) && inlineLevel < 5) {
|
|
70040
70101
|
const symbol = getResolvedSymbol(expr);
|
|
70041
|
-
|
|
70042
|
-
|
|
70043
|
-
|
|
70044
|
-
|
|
70045
|
-
|
|
70046
|
-
|
|
70047
|
-
return result;
|
|
70048
|
-
}
|
|
70102
|
+
const inlineExpression = getNarrowableInlineExpression(symbol);
|
|
70103
|
+
if (inlineExpression && isConstantReference(reference)) {
|
|
70104
|
+
inlineLevel++;
|
|
70105
|
+
const result = narrowType(type, inlineExpression, assumeTrue);
|
|
70106
|
+
inlineLevel--;
|
|
70107
|
+
return result;
|
|
70049
70108
|
}
|
|
70050
70109
|
}
|
|
70051
70110
|
// falls through
|
|
@@ -70080,6 +70139,14 @@ function createTypeChecker(host) {
|
|
|
70080
70139
|
return type;
|
|
70081
70140
|
}
|
|
70082
70141
|
}
|
|
70142
|
+
function getNarrowableInlineExpression(symbol) {
|
|
70143
|
+
if (isConstantVariable(symbol)) {
|
|
70144
|
+
const declaration = symbol.valueDeclaration;
|
|
70145
|
+
if (declaration && isVariableDeclaration(declaration) && !declaration.type && declaration.initializer) {
|
|
70146
|
+
return declaration.initializer;
|
|
70147
|
+
}
|
|
70148
|
+
}
|
|
70149
|
+
}
|
|
70083
70150
|
function getTypeOfSymbolAtLocation(symbol, location) {
|
|
70084
70151
|
symbol = getExportSymbolOfValueSymbolIfExported(symbol);
|
|
70085
70152
|
if (location.kind === 80 /* Identifier */ || location.kind === 81 /* PrivateIdentifier */) {
|
|
@@ -70269,11 +70336,11 @@ function createTypeChecker(host) {
|
|
|
70269
70336
|
));
|
|
70270
70337
|
return contextualType && !isGenericType(contextualType);
|
|
70271
70338
|
}
|
|
70272
|
-
function getNarrowableTypeForReference(type, reference, checkMode) {
|
|
70339
|
+
function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
|
|
70273
70340
|
if (isNoInferType(type)) {
|
|
70274
70341
|
type = type.baseType;
|
|
70275
70342
|
}
|
|
70276
|
-
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70343
|
+
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70277
70344
|
return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
|
|
70278
70345
|
}
|
|
70279
70346
|
function isExportOrExportExpression(location) {
|
|
@@ -71398,9 +71465,16 @@ function createTypeChecker(host) {
|
|
|
71398
71465
|
function getContextualTypeForReturnExpression(node, contextFlags) {
|
|
71399
71466
|
const func = getContainingFunction(node);
|
|
71400
71467
|
if (func) {
|
|
71468
|
+
const functionFlags = getFunctionFlags(func);
|
|
71469
|
+
const links = getNodeLinks(node);
|
|
71470
|
+
if (links.contextualReturnType) {
|
|
71471
|
+
if (functionFlags & 2 /* Async */) {
|
|
71472
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
71473
|
+
}
|
|
71474
|
+
return links.contextualReturnType;
|
|
71475
|
+
}
|
|
71401
71476
|
let contextualReturnType = getContextualReturnType(func, contextFlags);
|
|
71402
71477
|
if (contextualReturnType) {
|
|
71403
|
-
const functionFlags = getFunctionFlags(func);
|
|
71404
71478
|
if (functionFlags & 1 /* Generator */) {
|
|
71405
71479
|
const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
|
|
71406
71480
|
if (contextualReturnType.flags & 1048576 /* Union */) {
|
|
@@ -72098,6 +72172,13 @@ function createTypeChecker(host) {
|
|
|
72098
72172
|
if (index >= 0) {
|
|
72099
72173
|
return contextualTypes[index];
|
|
72100
72174
|
}
|
|
72175
|
+
const links = getNodeLinks(node);
|
|
72176
|
+
if (links.contextualReturnType) {
|
|
72177
|
+
if (node.flags & 65536 /* AwaitContext */) {
|
|
72178
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
72179
|
+
}
|
|
72180
|
+
return links.contextualReturnType;
|
|
72181
|
+
}
|
|
72101
72182
|
const { parent } = node;
|
|
72102
72183
|
switch (parent.kind) {
|
|
72103
72184
|
case 260 /* VariableDeclaration */:
|
|
@@ -82987,34 +83068,234 @@ function createTypeChecker(host) {
|
|
|
82987
83068
|
}
|
|
82988
83069
|
const signature = getSignatureFromDeclaration(container);
|
|
82989
83070
|
const returnType = getReturnTypeOfSignature(signature);
|
|
82990
|
-
const functionFlags = getFunctionFlags(container);
|
|
82991
83071
|
if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
|
|
82992
|
-
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
|
82993
83072
|
if (container.kind === 178 /* SetAccessor */) {
|
|
82994
83073
|
if (node.expression) {
|
|
82995
83074
|
error(node, Diagnostics.Setters_cannot_return_a_value);
|
|
82996
83075
|
}
|
|
82997
83076
|
} else if (container.kind === 176 /* Constructor */) {
|
|
83077
|
+
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
|
82998
83078
|
if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType, returnType, node, node.expression)) {
|
|
82999
83079
|
error(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
|
|
83000
83080
|
}
|
|
83001
83081
|
} else if (getReturnTypeFromAnnotation(container)) {
|
|
83002
|
-
|
|
83003
|
-
const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83004
|
-
exprType,
|
|
83005
|
-
/*withAlias*/
|
|
83006
|
-
false,
|
|
83007
|
-
node,
|
|
83008
|
-
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83009
|
-
) : exprType;
|
|
83010
|
-
if (unwrappedReturnType) {
|
|
83011
|
-
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, node, node.expression);
|
|
83012
|
-
}
|
|
83082
|
+
checkReturnStatementExpression(container, returnType, node, node.expression);
|
|
83013
83083
|
}
|
|
83014
83084
|
} else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
|
|
83015
83085
|
error(node, Diagnostics.Not_all_code_paths_return_a_value);
|
|
83016
83086
|
}
|
|
83017
83087
|
}
|
|
83088
|
+
function checkReturnStatementExpression(container, returnType, node, expr) {
|
|
83089
|
+
const functionFlags = getFunctionFlags(container);
|
|
83090
|
+
const unwrappedReturnType = unwrapReturnType(returnType, functionFlags) ?? returnType;
|
|
83091
|
+
if (expr) {
|
|
83092
|
+
const unwrappedExpr = skipParentheses(expr);
|
|
83093
|
+
if (isConditionalExpression(unwrappedExpr)) {
|
|
83094
|
+
return checkReturnConditionalExpression(container, returnType, node, unwrappedExpr);
|
|
83095
|
+
}
|
|
83096
|
+
}
|
|
83097
|
+
const exprType = expr ? checkExpressionCached(expr) : undefinedType;
|
|
83098
|
+
const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83099
|
+
exprType,
|
|
83100
|
+
/*withAlias*/
|
|
83101
|
+
false,
|
|
83102
|
+
node,
|
|
83103
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83104
|
+
) : exprType;
|
|
83105
|
+
const errorNode = node.expression && isConditionalExpression(skipParentheses(node.expression)) ? expr : node;
|
|
83106
|
+
if (checkTypeAssignableTo(
|
|
83107
|
+
unwrappedExprType,
|
|
83108
|
+
unwrappedReturnType,
|
|
83109
|
+
/*errorNode*/
|
|
83110
|
+
void 0
|
|
83111
|
+
)) {
|
|
83112
|
+
return;
|
|
83113
|
+
}
|
|
83114
|
+
if (!isGenericIndexedOrConditionalReturnType(unwrappedReturnType)) {
|
|
83115
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, expr);
|
|
83116
|
+
return;
|
|
83117
|
+
}
|
|
83118
|
+
const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
|
|
83119
|
+
container,
|
|
83120
|
+
/*includeThisTypes*/
|
|
83121
|
+
false
|
|
83122
|
+
), getEffectiveTypeParameterDeclarations(container));
|
|
83123
|
+
const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
|
|
83124
|
+
if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
|
|
83125
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, expr);
|
|
83126
|
+
return;
|
|
83127
|
+
}
|
|
83128
|
+
let narrowPosition = node;
|
|
83129
|
+
let narrowFlowNode = node.flowNode;
|
|
83130
|
+
if (expr && isConditionalExpression(expr.parent)) {
|
|
83131
|
+
narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
|
|
83132
|
+
narrowPosition = expr;
|
|
83133
|
+
}
|
|
83134
|
+
if (!narrowFlowNode) {
|
|
83135
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, expr);
|
|
83136
|
+
return;
|
|
83137
|
+
}
|
|
83138
|
+
const narrowed = mapDefined(narrowableTypeParameters, ([typeParam, symbol, reference]) => {
|
|
83139
|
+
const narrowReference = factory.cloneNode(reference);
|
|
83140
|
+
narrowReference.id = void 0;
|
|
83141
|
+
getNodeLinks(narrowReference).resolvedSymbol = symbol;
|
|
83142
|
+
setParent(narrowReference, narrowPosition.parent);
|
|
83143
|
+
narrowReference.flowNode = narrowFlowNode;
|
|
83144
|
+
const initialType = getNarrowableTypeForReference(
|
|
83145
|
+
typeParam,
|
|
83146
|
+
narrowReference,
|
|
83147
|
+
/*checkMode*/
|
|
83148
|
+
void 0,
|
|
83149
|
+
/*forReturnTypeNarrowing*/
|
|
83150
|
+
true
|
|
83151
|
+
);
|
|
83152
|
+
if (initialType === typeParam) {
|
|
83153
|
+
return void 0;
|
|
83154
|
+
}
|
|
83155
|
+
const flowType = getFlowTypeOfReference(narrowReference, initialType);
|
|
83156
|
+
const exprType2 = getTypeFromFlowType(flowType);
|
|
83157
|
+
if (isTypeAny(exprType2) || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
|
|
83158
|
+
return void 0;
|
|
83159
|
+
}
|
|
83160
|
+
const narrowedType = getSubstitutionType(
|
|
83161
|
+
typeParam,
|
|
83162
|
+
exprType2,
|
|
83163
|
+
/*isNarrowed*/
|
|
83164
|
+
true
|
|
83165
|
+
);
|
|
83166
|
+
return [typeParam, narrowedType];
|
|
83167
|
+
});
|
|
83168
|
+
const narrowMapper = createTypeMapper(narrowed.map(([tp, _]) => tp), narrowed.map(([_, t]) => t));
|
|
83169
|
+
const narrowedReturnType = instantiateType(
|
|
83170
|
+
unwrappedReturnType,
|
|
83171
|
+
narrowMapper
|
|
83172
|
+
);
|
|
83173
|
+
if (expr) {
|
|
83174
|
+
const links = getNodeLinks(expr);
|
|
83175
|
+
if (!links.contextualReturnType) {
|
|
83176
|
+
links.contextualReturnType = narrowedReturnType;
|
|
83177
|
+
}
|
|
83178
|
+
}
|
|
83179
|
+
const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
|
|
83180
|
+
const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83181
|
+
narrowedExprType,
|
|
83182
|
+
/*withAlias*/
|
|
83183
|
+
false,
|
|
83184
|
+
node,
|
|
83185
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83186
|
+
) : narrowedExprType;
|
|
83187
|
+
checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, expr);
|
|
83188
|
+
}
|
|
83189
|
+
function checkReturnConditionalExpression(container, returnType, node, expr) {
|
|
83190
|
+
checkExpression(expr.condition);
|
|
83191
|
+
checkReturnStatementExpression(container, returnType, node, expr.whenTrue);
|
|
83192
|
+
checkReturnStatementExpression(container, returnType, node, expr.whenFalse);
|
|
83193
|
+
}
|
|
83194
|
+
function getNarrowableTypeParameters(candidates) {
|
|
83195
|
+
const narrowableParams = [];
|
|
83196
|
+
for (const typeParam of candidates) {
|
|
83197
|
+
const constraint = getConstraintOfTypeParameter(typeParam);
|
|
83198
|
+
if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
|
|
83199
|
+
if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
|
|
83200
|
+
const container = typeParam.symbol.declarations[0].parent;
|
|
83201
|
+
if (!isFunctionLike(container)) continue;
|
|
83202
|
+
let reference;
|
|
83203
|
+
let hasInvalidReference = false;
|
|
83204
|
+
for (const paramDecl of container.parameters) {
|
|
83205
|
+
const typeNode = paramDecl.type;
|
|
83206
|
+
if (!typeNode) continue;
|
|
83207
|
+
if (isTypeParameterReferenced(typeParam, typeNode)) {
|
|
83208
|
+
let candidateReference;
|
|
83209
|
+
if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
|
|
83210
|
+
if (reference) {
|
|
83211
|
+
hasInvalidReference = true;
|
|
83212
|
+
break;
|
|
83213
|
+
}
|
|
83214
|
+
reference = candidateReference;
|
|
83215
|
+
continue;
|
|
83216
|
+
}
|
|
83217
|
+
hasInvalidReference = true;
|
|
83218
|
+
break;
|
|
83219
|
+
}
|
|
83220
|
+
}
|
|
83221
|
+
if (!hasInvalidReference && reference) {
|
|
83222
|
+
const symbol = getResolvedSymbol(reference);
|
|
83223
|
+
if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
|
|
83224
|
+
}
|
|
83225
|
+
}
|
|
83226
|
+
}
|
|
83227
|
+
return narrowableParams;
|
|
83228
|
+
function getValidParameterReference(paramDecl, constraint) {
|
|
83229
|
+
if (!isIdentifier(paramDecl.name)) return;
|
|
83230
|
+
if (paramDecl.questionToken && !containsUndefinedType(constraint)) return;
|
|
83231
|
+
return paramDecl.name;
|
|
83232
|
+
}
|
|
83233
|
+
function isReferenceToTypeParameter(typeParam, node) {
|
|
83234
|
+
return getTypeFromTypeReference(node) === typeParam;
|
|
83235
|
+
}
|
|
83236
|
+
function isTypeParameterReferenced(typeParam, node) {
|
|
83237
|
+
return isReferenced(node);
|
|
83238
|
+
function isReferenced(node2) {
|
|
83239
|
+
if (isTypeReferenceNode(node2)) {
|
|
83240
|
+
return isReferenceToTypeParameter(typeParam, node2);
|
|
83241
|
+
}
|
|
83242
|
+
if (isTypeQueryNode(node2)) {
|
|
83243
|
+
return isTypeParameterPossiblyReferenced(typeParam, node2);
|
|
83244
|
+
}
|
|
83245
|
+
return !!forEachChild(node2, isReferenced);
|
|
83246
|
+
}
|
|
83247
|
+
}
|
|
83248
|
+
}
|
|
83249
|
+
function isNarrowableReturnType(returnType) {
|
|
83250
|
+
return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
|
|
83251
|
+
}
|
|
83252
|
+
function isNarrowableConditionalType(type, mapper) {
|
|
83253
|
+
const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
|
|
83254
|
+
const mapped = getMappedType(t, mapper);
|
|
83255
|
+
if (isNarrowingSubstitutionType(mapped)) {
|
|
83256
|
+
return mapped.baseType;
|
|
83257
|
+
}
|
|
83258
|
+
return mapped;
|
|
83259
|
+
});
|
|
83260
|
+
const id = `${type.id}:${getTypeListId(typeArguments)}`;
|
|
83261
|
+
let result = narrowableReturnTypeCache.get(id);
|
|
83262
|
+
if (result === void 0) {
|
|
83263
|
+
const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
|
|
83264
|
+
const instantiatedType = instantiateType(type, nonNarrowingMapper);
|
|
83265
|
+
result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
|
|
83266
|
+
narrowableReturnTypeCache.set(id, result);
|
|
83267
|
+
}
|
|
83268
|
+
return result;
|
|
83269
|
+
}
|
|
83270
|
+
function isNarrowableConditionalTypeWorker(type) {
|
|
83271
|
+
if (!type.root.isDistributive) {
|
|
83272
|
+
return false;
|
|
83273
|
+
}
|
|
83274
|
+
if (type.root.inferTypeParameters) {
|
|
83275
|
+
return false;
|
|
83276
|
+
}
|
|
83277
|
+
if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
|
|
83278
|
+
return false;
|
|
83279
|
+
}
|
|
83280
|
+
const constraintType = getConstraintOfTypeParameter(type.checkType);
|
|
83281
|
+
if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
|
|
83282
|
+
return false;
|
|
83283
|
+
}
|
|
83284
|
+
if (!everyType(type.extendsType, (extendsType) => some(
|
|
83285
|
+
constraintType.types,
|
|
83286
|
+
(constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
|
|
83287
|
+
))) {
|
|
83288
|
+
return false;
|
|
83289
|
+
}
|
|
83290
|
+
const trueType2 = getTrueTypeFromConditionalType(type);
|
|
83291
|
+
const falseType2 = getFalseTypeFromConditionalType(type);
|
|
83292
|
+
const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
|
|
83293
|
+
const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
|
|
83294
|
+
return isValidTrueType && isValidFalseType;
|
|
83295
|
+
}
|
|
83296
|
+
function isConditionalType(type) {
|
|
83297
|
+
return !!(type.flags & 16777216 /* Conditional */);
|
|
83298
|
+
}
|
|
83018
83299
|
function checkWithStatement(node) {
|
|
83019
83300
|
if (!checkGrammarStatementInAmbientContext(node)) {
|
|
83020
83301
|
if (node.flags & 65536 /* AwaitContext */) {
|
|
@@ -112132,7 +112413,7 @@ function createGetIsolatedDeclarationErrors(resolver) {
|
|
|
112132
112413
|
if (!addUndefined && node.initializer) {
|
|
112133
112414
|
return createExpressionError(node.initializer);
|
|
112134
112415
|
}
|
|
112135
|
-
const message = addUndefined ? Diagnostics.
|
|
112416
|
+
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];
|
|
112136
112417
|
const diag2 = createDiagnosticForNode(node, message);
|
|
112137
112418
|
const targetStr = getTextOfNode(
|
|
112138
112419
|
node.name,
|
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.
|
|
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
|
-
|
|
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
|
|
63751
|
-
return
|
|
63763
|
+
function isNarrowingSubstitutionType(type) {
|
|
63764
|
+
return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowedType */);
|
|
63752
63765
|
}
|
|
63753
|
-
function
|
|
63754
|
-
|
|
63766
|
+
function getSubstitutionType(baseType, constraint, isNarrowed) {
|
|
63767
|
+
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
|
|
63768
|
+
}
|
|
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(
|
|
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 */) && (
|
|
66004
|
-
if (
|
|
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(
|
|
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
|
-
|
|
66988
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74645
|
-
|
|
74646
|
-
|
|
74647
|
-
|
|
74648
|
-
|
|
74649
|
-
|
|
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) {
|
|
@@ -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 */:
|
|
@@ -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
|
-
|
|
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.
|
|
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.
|
|
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
|
];
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@typescript-deploys/pr-build",
|
|
3
3
|
"author": "Microsoft Corp.",
|
|
4
4
|
"homepage": "https://www.typescriptlang.org/",
|
|
5
|
-
"version": "5.7.0-pr-
|
|
5
|
+
"version": "5.7.0-pr-56941-53",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"description": "TypeScript is a language for application scale JavaScript development",
|
|
8
8
|
"keywords": [
|