@typescript-deploys/pr-build 5.9.0-pr-61420-2 → 5.9.0-pr-61359-4
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 +479 -67
- package/lib/typescript.js +479 -70
- 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.9";
|
|
21
|
-
var version = `${versionMajorMinor}.0-insiders.
|
|
21
|
+
var version = `${versionMajorMinor}.0-insiders.20250320`;
|
|
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["IsNarrowingType"] = 16777216] = "IsNarrowingType";
|
|
3683
3684
|
ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
|
|
3684
3685
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
|
|
3685
3686
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
|
|
@@ -44902,6 +44903,8 @@ function getContainerFlags(node) {
|
|
|
44902
44903
|
case 185 /* ConstructorType */:
|
|
44903
44904
|
case 175 /* ClassStaticBlockDeclaration */:
|
|
44904
44905
|
return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */;
|
|
44906
|
+
case 351 /* JSDocImportTag */:
|
|
44907
|
+
return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */;
|
|
44905
44908
|
case 218 /* FunctionExpression */:
|
|
44906
44909
|
case 219 /* ArrowFunction */:
|
|
44907
44910
|
return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 16 /* IsFunctionExpression */;
|
|
@@ -46163,7 +46166,6 @@ function createTypeChecker(host) {
|
|
|
46163
46166
|
};
|
|
46164
46167
|
var cancellationToken;
|
|
46165
46168
|
var scanner;
|
|
46166
|
-
var fileIndexMap = new Map(host.getSourceFiles().map((file, i) => [file, i]));
|
|
46167
46169
|
var Symbol13 = objectAllocator.getSymbolConstructor();
|
|
46168
46170
|
var Type7 = objectAllocator.getTypeConstructor();
|
|
46169
46171
|
var Signature5 = objectAllocator.getSignatureConstructor();
|
|
@@ -47177,6 +47179,7 @@ function createTypeChecker(host) {
|
|
|
47177
47179
|
[".jsx", ".jsx"],
|
|
47178
47180
|
[".json", ".json"]
|
|
47179
47181
|
];
|
|
47182
|
+
var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
|
|
47180
47183
|
initializeTypeChecker();
|
|
47181
47184
|
return checker;
|
|
47182
47185
|
function isDefinitelyReferenceToGlobalSymbolObject(node) {
|
|
@@ -49802,7 +49805,6 @@ function createTypeChecker(host) {
|
|
|
49802
49805
|
(result || (result = [])).push(symbol);
|
|
49803
49806
|
}
|
|
49804
49807
|
});
|
|
49805
|
-
result == null ? void 0 : result.sort(compareSymbols);
|
|
49806
49808
|
return result || emptyArray;
|
|
49807
49809
|
}
|
|
49808
49810
|
function isNamedMember(member, escapedName) {
|
|
@@ -50408,10 +50410,11 @@ function createTypeChecker(host) {
|
|
|
50408
50410
|
serializeExistingTypeNode(context, typeNode, addUndefined) {
|
|
50409
50411
|
return serializeExistingTypeNode(context, typeNode, !!addUndefined);
|
|
50410
50412
|
},
|
|
50411
|
-
serializeReturnTypeForSignature(syntacticContext, signatureDeclaration) {
|
|
50413
|
+
serializeReturnTypeForSignature(syntacticContext, signatureDeclaration, symbol) {
|
|
50412
50414
|
const context = syntacticContext;
|
|
50413
50415
|
const signature = getSignatureFromDeclaration(signatureDeclaration);
|
|
50414
|
-
|
|
50416
|
+
symbol ?? (symbol = getSymbolOfDeclaration(signatureDeclaration));
|
|
50417
|
+
const returnType = context.enclosingSymbolTypes.get(getSymbolId(symbol)) ?? instantiateType(getReturnTypeOfSignature(signature), context.mapper);
|
|
50415
50418
|
return serializeInferredReturnTypeForSignature(context, signature, returnType);
|
|
50416
50419
|
},
|
|
50417
50420
|
serializeTypeOfExpression(syntacticContext, expr) {
|
|
@@ -50425,7 +50428,7 @@ function createTypeChecker(host) {
|
|
|
50425
50428
|
symbol ?? (symbol = getSymbolOfDeclaration(declaration));
|
|
50426
50429
|
let type = (_a = context.enclosingSymbolTypes) == null ? void 0 : _a.get(getSymbolId(symbol));
|
|
50427
50430
|
if (type === void 0) {
|
|
50428
|
-
type = symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) ? instantiateType(getWidenedLiteralType(getTypeOfSymbol(symbol)), context.mapper) : errorType;
|
|
50431
|
+
type = symbol.flags & 98304 /* Accessor */ && declaration.kind === 178 /* SetAccessor */ ? instantiateType(getWriteTypeOfSymbol(symbol), context.mapper) : symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) ? instantiateType(getWidenedLiteralType(getTypeOfSymbol(symbol)), context.mapper) : errorType;
|
|
50429
50432
|
}
|
|
50430
50433
|
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
|
|
50431
50434
|
if (addUndefinedForParameter) {
|
|
@@ -51574,12 +51577,13 @@ function createTypeChecker(host) {
|
|
|
51574
51577
|
if (propertySymbol.flags & 98304 /* Accessor */) {
|
|
51575
51578
|
const writeType = getWriteTypeOfSymbol(propertySymbol);
|
|
51576
51579
|
if (propertyType !== writeType && !isErrorType(propertyType) && !isErrorType(writeType)) {
|
|
51580
|
+
const symbolMapper = getSymbolLinks(propertySymbol).mapper;
|
|
51577
51581
|
const getterDeclaration = getDeclarationOfKind(propertySymbol, 177 /* GetAccessor */);
|
|
51578
51582
|
const getterSignature = getSignatureFromDeclaration(getterDeclaration);
|
|
51579
51583
|
typeElements.push(
|
|
51580
51584
|
setCommentRange2(
|
|
51581
51585
|
context,
|
|
51582
|
-
signatureToSignatureDeclarationHelper(getterSignature, 177 /* GetAccessor */, context, { name: propertyName }),
|
|
51586
|
+
signatureToSignatureDeclarationHelper(symbolMapper ? instantiateSignature(getterSignature, symbolMapper) : getterSignature, 177 /* GetAccessor */, context, { name: propertyName }),
|
|
51583
51587
|
getterDeclaration
|
|
51584
51588
|
)
|
|
51585
51589
|
);
|
|
@@ -51588,7 +51592,7 @@ function createTypeChecker(host) {
|
|
|
51588
51592
|
typeElements.push(
|
|
51589
51593
|
setCommentRange2(
|
|
51590
51594
|
context,
|
|
51591
|
-
signatureToSignatureDeclarationHelper(setterSignature, 178 /* SetAccessor */, context, { name: propertyName }),
|
|
51595
|
+
signatureToSignatureDeclarationHelper(symbolMapper ? instantiateSignature(setterSignature, symbolMapper) : setterSignature, 178 /* SetAccessor */, context, { name: propertyName }),
|
|
51592
51596
|
setterDeclaration
|
|
51593
51597
|
)
|
|
51594
51598
|
);
|
|
@@ -52731,13 +52735,13 @@ function createTypeChecker(host) {
|
|
|
52731
52735
|
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
|
|
52732
52736
|
const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
|
|
52733
52737
|
if (decl) {
|
|
52738
|
+
const restore = addSymbolTypeToContext(context, symbol, type);
|
|
52734
52739
|
if (isAccessor(decl)) {
|
|
52735
52740
|
result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
|
|
52736
52741
|
} else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
|
|
52737
|
-
const restore = addSymbolTypeToContext(context, symbol, type);
|
|
52738
52742
|
result = syntacticNodeBuilder.serializeTypeOfDeclaration(decl, symbol, context);
|
|
52739
|
-
restore();
|
|
52740
52743
|
}
|
|
52744
|
+
restore();
|
|
52741
52745
|
}
|
|
52742
52746
|
if (!result) {
|
|
52743
52747
|
if (addUndefinedForParameter) {
|
|
@@ -59439,11 +59443,14 @@ function createTypeChecker(host) {
|
|
|
59439
59443
|
function isNoInferType(type) {
|
|
59440
59444
|
return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
|
|
59441
59445
|
}
|
|
59442
|
-
function
|
|
59443
|
-
return
|
|
59446
|
+
function isNarrowingSubstitutionType(type) {
|
|
59447
|
+
return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
|
|
59444
59448
|
}
|
|
59445
|
-
function
|
|
59446
|
-
|
|
59449
|
+
function getSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59450
|
+
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
|
|
59451
|
+
}
|
|
59452
|
+
function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59453
|
+
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
|
|
59447
59454
|
const cached = substitutionTypes.get(id);
|
|
59448
59455
|
if (cached) {
|
|
59449
59456
|
return cached;
|
|
@@ -59451,6 +59458,9 @@ function createTypeChecker(host) {
|
|
|
59451
59458
|
const result = createType(33554432 /* Substitution */);
|
|
59452
59459
|
result.baseType = baseType;
|
|
59453
59460
|
result.constraint = constraint;
|
|
59461
|
+
if (isNarrowed) {
|
|
59462
|
+
result.objectFlags |= 16777216 /* IsNarrowingType */;
|
|
59463
|
+
}
|
|
59454
59464
|
substitutionTypes.set(id, result);
|
|
59455
59465
|
return result;
|
|
59456
59466
|
}
|
|
@@ -61656,7 +61666,7 @@ function createTypeChecker(host) {
|
|
|
61656
61666
|
function isDeferredType(type, checkTuples) {
|
|
61657
61667
|
return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
|
|
61658
61668
|
}
|
|
61659
|
-
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
|
|
61669
|
+
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
|
|
61660
61670
|
let result;
|
|
61661
61671
|
let extraTypes;
|
|
61662
61672
|
let tailCount = 0;
|
|
@@ -61673,10 +61683,11 @@ function createTypeChecker(host) {
|
|
|
61673
61683
|
if (checkType === wildcardType || extendsType === wildcardType) {
|
|
61674
61684
|
return wildcardType;
|
|
61675
61685
|
}
|
|
61686
|
+
const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
|
|
61676
61687
|
const checkTypeNode = skipTypeParentheses(root.node.checkType);
|
|
61677
61688
|
const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
|
|
61678
61689
|
const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
|
|
61679
|
-
const checkTypeDeferred = isDeferredType(
|
|
61690
|
+
const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
|
|
61680
61691
|
let combinedMapper;
|
|
61681
61692
|
if (root.inferTypeParameters) {
|
|
61682
61693
|
const context = createInferenceContext(
|
|
@@ -61695,8 +61706,8 @@ function createTypeChecker(host) {
|
|
|
61695
61706
|
}
|
|
61696
61707
|
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
|
|
61697
61708
|
if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
|
|
61698
|
-
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (
|
|
61699
|
-
if (
|
|
61709
|
+
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
|
|
61710
|
+
if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
|
|
61700
61711
|
(extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
|
|
61701
61712
|
}
|
|
61702
61713
|
const falseType2 = getTypeFromTypeNode(root.node.falseType);
|
|
@@ -61713,7 +61724,7 @@ function createTypeChecker(host) {
|
|
|
61713
61724
|
result = instantiateType(falseType2, mapper);
|
|
61714
61725
|
break;
|
|
61715
61726
|
}
|
|
61716
|
-
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(
|
|
61727
|
+
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
|
|
61717
61728
|
const trueType2 = getTypeFromTypeNode(root.node.trueType);
|
|
61718
61729
|
const trueMapper = combinedMapper || mapper;
|
|
61719
61730
|
if (canTailRecurse(trueType2, trueMapper)) {
|
|
@@ -62679,8 +62690,44 @@ function createTypeChecker(host) {
|
|
|
62679
62690
|
if (!result) {
|
|
62680
62691
|
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
|
|
62681
62692
|
const checkType = root.checkType;
|
|
62682
|
-
|
|
62683
|
-
|
|
62693
|
+
let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
|
|
62694
|
+
let narrowingBaseType;
|
|
62695
|
+
const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(
|
|
62696
|
+
type,
|
|
62697
|
+
/*hadNonPrimitiveExtendsType*/
|
|
62698
|
+
[],
|
|
62699
|
+
mapper
|
|
62700
|
+
);
|
|
62701
|
+
if (forNarrowing) {
|
|
62702
|
+
narrowingBaseType = distributionType.baseType;
|
|
62703
|
+
distributionType = getReducedType(distributionType.constraint);
|
|
62704
|
+
}
|
|
62705
|
+
if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
|
|
62706
|
+
if (narrowingBaseType) {
|
|
62707
|
+
result = mapTypeToIntersection(
|
|
62708
|
+
distributionType,
|
|
62709
|
+
(t) => getConditionalType(
|
|
62710
|
+
root,
|
|
62711
|
+
prependTypeMapping(checkType, getSubstitutionType(
|
|
62712
|
+
narrowingBaseType,
|
|
62713
|
+
t,
|
|
62714
|
+
/*isNarrowed*/
|
|
62715
|
+
true
|
|
62716
|
+
), newMapper),
|
|
62717
|
+
forConstraint,
|
|
62718
|
+
/*aliasSymbol*/
|
|
62719
|
+
void 0,
|
|
62720
|
+
/*aliasTypeArguments*/
|
|
62721
|
+
void 0,
|
|
62722
|
+
forNarrowing
|
|
62723
|
+
)
|
|
62724
|
+
);
|
|
62725
|
+
} else {
|
|
62726
|
+
result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
|
|
62727
|
+
}
|
|
62728
|
+
} else {
|
|
62729
|
+
result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
|
|
62730
|
+
}
|
|
62684
62731
|
root.instantiations.set(id, result);
|
|
62685
62732
|
}
|
|
62686
62733
|
return result;
|
|
@@ -63823,10 +63870,12 @@ function createTypeChecker(host) {
|
|
|
63823
63870
|
function shouldNormalizeIntersection(type) {
|
|
63824
63871
|
let hasInstantiable = false;
|
|
63825
63872
|
let hasNullableOrEmpty = false;
|
|
63873
|
+
let hasSubstitution = false;
|
|
63826
63874
|
for (const t of type.types) {
|
|
63827
63875
|
hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
|
|
63828
63876
|
hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
|
|
63829
|
-
|
|
63877
|
+
hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
|
|
63878
|
+
if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
|
|
63830
63879
|
}
|
|
63831
63880
|
return false;
|
|
63832
63881
|
}
|
|
@@ -68986,6 +69035,18 @@ function createTypeChecker(host) {
|
|
|
68986
69035
|
}
|
|
68987
69036
|
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
|
|
68988
69037
|
}
|
|
69038
|
+
function mapTypeToIntersection(type, mapper) {
|
|
69039
|
+
if (type.flags & 131072 /* Never */) {
|
|
69040
|
+
return type;
|
|
69041
|
+
}
|
|
69042
|
+
if (!(type.flags & 1048576 /* Union */)) {
|
|
69043
|
+
return mapper(type);
|
|
69044
|
+
}
|
|
69045
|
+
const origin = type.origin;
|
|
69046
|
+
const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
|
|
69047
|
+
const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
|
|
69048
|
+
return getIntersectionType(mappedTypes);
|
|
69049
|
+
}
|
|
68989
69050
|
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
|
|
68990
69051
|
return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
|
|
68991
69052
|
}
|
|
@@ -70570,11 +70631,11 @@ function createTypeChecker(host) {
|
|
|
70570
70631
|
));
|
|
70571
70632
|
return contextualType && !isGenericType(contextualType);
|
|
70572
70633
|
}
|
|
70573
|
-
function getNarrowableTypeForReference(type, reference, checkMode) {
|
|
70634
|
+
function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
|
|
70574
70635
|
if (isNoInferType(type)) {
|
|
70575
70636
|
type = type.baseType;
|
|
70576
70637
|
}
|
|
70577
|
-
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70638
|
+
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70578
70639
|
return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
|
|
70579
70640
|
}
|
|
70580
70641
|
function isExportOrExportExpression(location) {
|
|
@@ -71701,9 +71762,16 @@ function createTypeChecker(host) {
|
|
|
71701
71762
|
function getContextualTypeForReturnExpression(node, contextFlags) {
|
|
71702
71763
|
const func = getContainingFunction(node);
|
|
71703
71764
|
if (func) {
|
|
71765
|
+
const functionFlags = getFunctionFlags(func);
|
|
71766
|
+
const links = getNodeLinks(node);
|
|
71767
|
+
if (links.contextualReturnType) {
|
|
71768
|
+
if (functionFlags & 2 /* Async */) {
|
|
71769
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
71770
|
+
}
|
|
71771
|
+
return links.contextualReturnType;
|
|
71772
|
+
}
|
|
71704
71773
|
let contextualReturnType = getContextualReturnType(func, contextFlags);
|
|
71705
71774
|
if (contextualReturnType) {
|
|
71706
|
-
const functionFlags = getFunctionFlags(func);
|
|
71707
71775
|
if (functionFlags & 1 /* Generator */) {
|
|
71708
71776
|
const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
|
|
71709
71777
|
if (contextualReturnType.flags & 1048576 /* Union */) {
|
|
@@ -72401,6 +72469,13 @@ function createTypeChecker(host) {
|
|
|
72401
72469
|
if (index >= 0) {
|
|
72402
72470
|
return contextualTypes[index];
|
|
72403
72471
|
}
|
|
72472
|
+
const links = getNodeLinks(node);
|
|
72473
|
+
if (links.contextualReturnType) {
|
|
72474
|
+
if (node.flags & 65536 /* AwaitContext */) {
|
|
72475
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
72476
|
+
}
|
|
72477
|
+
return links.contextualReturnType;
|
|
72478
|
+
}
|
|
72404
72479
|
const { parent } = node;
|
|
72405
72480
|
switch (parent.kind) {
|
|
72406
72481
|
case 260 /* VariableDeclaration */:
|
|
@@ -74437,13 +74512,15 @@ function createTypeChecker(host) {
|
|
|
74437
74512
|
function getSuggestionForSymbolNameLookup(symbols, name, meaning) {
|
|
74438
74513
|
const symbol = getSymbol(symbols, name, meaning);
|
|
74439
74514
|
if (symbol) return symbol;
|
|
74440
|
-
let candidates
|
|
74515
|
+
let candidates;
|
|
74441
74516
|
if (symbols === globals) {
|
|
74442
74517
|
const primitives = mapDefined(
|
|
74443
74518
|
["string", "number", "boolean", "object", "bigint", "symbol"],
|
|
74444
74519
|
(s) => symbols.has(s.charAt(0).toUpperCase() + s.slice(1)) ? createSymbol(524288 /* TypeAlias */, s) : void 0
|
|
74445
74520
|
);
|
|
74446
|
-
candidates =
|
|
74521
|
+
candidates = primitives.concat(arrayFrom(symbols.values()));
|
|
74522
|
+
} else {
|
|
74523
|
+
candidates = arrayFrom(symbols.values());
|
|
74447
74524
|
}
|
|
74448
74525
|
return getSpellingSuggestionForName(unescapeLeadingUnderscores(name), candidates, meaning);
|
|
74449
74526
|
}
|
|
@@ -74463,7 +74540,7 @@ function createTypeChecker(host) {
|
|
|
74463
74540
|
return result;
|
|
74464
74541
|
}
|
|
74465
74542
|
function getSuggestedSymbolForNonexistentModule(name, targetModule) {
|
|
74466
|
-
return targetModule.exports && getSpellingSuggestionForName(idText(name), getExportsOfModuleAsArray(targetModule)
|
|
74543
|
+
return targetModule.exports && getSpellingSuggestionForName(idText(name), getExportsOfModuleAsArray(targetModule), 2623475 /* ModuleMember */);
|
|
74467
74544
|
}
|
|
74468
74545
|
function getSuggestionForNonexistentIndexSignature(objectType, expr, keyedType) {
|
|
74469
74546
|
function hasProp(name) {
|
|
@@ -76783,8 +76860,8 @@ function createTypeChecker(host) {
|
|
|
76783
76860
|
grammarErrorOnNode(node, Diagnostics.This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead);
|
|
76784
76861
|
}
|
|
76785
76862
|
if (compilerOptions.erasableSyntaxOnly) {
|
|
76786
|
-
const start = node.
|
|
76787
|
-
const end =
|
|
76863
|
+
const start = skipTrivia(file.text, node.pos);
|
|
76864
|
+
const end = node.expression.pos;
|
|
76788
76865
|
diagnostics.add(createFileDiagnostic(file, start, end - start, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled));
|
|
76789
76866
|
}
|
|
76790
76867
|
}
|
|
@@ -83413,7 +83490,374 @@ function createTypeChecker(host) {
|
|
|
83413
83490
|
) : exprType;
|
|
83414
83491
|
const effectiveExpr = expr && getEffectiveCheckNode(expr);
|
|
83415
83492
|
const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
|
|
83416
|
-
|
|
83493
|
+
if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
|
|
83494
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83495
|
+
return;
|
|
83496
|
+
}
|
|
83497
|
+
if (checkTypeAssignableTo(
|
|
83498
|
+
unwrappedExprType,
|
|
83499
|
+
unwrappedReturnType,
|
|
83500
|
+
/*errorNode*/
|
|
83501
|
+
void 0
|
|
83502
|
+
)) {
|
|
83503
|
+
return;
|
|
83504
|
+
}
|
|
83505
|
+
let narrowPosition = node;
|
|
83506
|
+
let narrowFlowNode = inReturnStatement && node.flowNode;
|
|
83507
|
+
if (expr && isConditionalExpression(expr.parent)) {
|
|
83508
|
+
narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
|
|
83509
|
+
narrowPosition = expr;
|
|
83510
|
+
}
|
|
83511
|
+
if (!narrowFlowNode) {
|
|
83512
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83513
|
+
return;
|
|
83514
|
+
}
|
|
83515
|
+
const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
|
|
83516
|
+
container,
|
|
83517
|
+
/*includeThisTypes*/
|
|
83518
|
+
false
|
|
83519
|
+
), getEffectiveTypeParameterDeclarations(container));
|
|
83520
|
+
const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
|
|
83521
|
+
if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
|
|
83522
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83523
|
+
return;
|
|
83524
|
+
}
|
|
83525
|
+
const narrowedTypeParameters = [];
|
|
83526
|
+
const narrowedTypes = [];
|
|
83527
|
+
for (const [typeParam, symbol, narrowReference] of narrowableTypeParameters) {
|
|
83528
|
+
resetNodeId(narrowReference);
|
|
83529
|
+
let baseReference = narrowReference;
|
|
83530
|
+
while (isAccessExpression(baseReference)) {
|
|
83531
|
+
baseReference = baseReference.expression;
|
|
83532
|
+
}
|
|
83533
|
+
getNodeLinks(baseReference).resolvedSymbol = symbol;
|
|
83534
|
+
setParent(narrowReference, narrowPosition.parent);
|
|
83535
|
+
narrowReference.flowNode = narrowFlowNode;
|
|
83536
|
+
const initialType = getNarrowableTypeForReference(
|
|
83537
|
+
typeParam,
|
|
83538
|
+
narrowReference,
|
|
83539
|
+
/*checkMode*/
|
|
83540
|
+
void 0,
|
|
83541
|
+
/*forReturnTypeNarrowing*/
|
|
83542
|
+
true
|
|
83543
|
+
);
|
|
83544
|
+
if (initialType === typeParam) {
|
|
83545
|
+
continue;
|
|
83546
|
+
}
|
|
83547
|
+
const flowType = getFlowTypeOfReference(narrowReference, initialType);
|
|
83548
|
+
const exprType2 = getTypeFromFlowType(flowType);
|
|
83549
|
+
if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
|
|
83550
|
+
continue;
|
|
83551
|
+
}
|
|
83552
|
+
const narrowedType = getSubstitutionType(
|
|
83553
|
+
typeParam,
|
|
83554
|
+
exprType2,
|
|
83555
|
+
/*isNarrowed*/
|
|
83556
|
+
true
|
|
83557
|
+
);
|
|
83558
|
+
narrowedTypeParameters.push(typeParam);
|
|
83559
|
+
narrowedTypes.push(narrowedType);
|
|
83560
|
+
}
|
|
83561
|
+
const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
|
|
83562
|
+
const narrowedReturnType = instantiateType(
|
|
83563
|
+
unwrappedReturnType,
|
|
83564
|
+
narrowMapper
|
|
83565
|
+
);
|
|
83566
|
+
if (expr) {
|
|
83567
|
+
const links = getNodeLinks(expr);
|
|
83568
|
+
if (!links.contextualReturnType) {
|
|
83569
|
+
links.contextualReturnType = narrowedReturnType;
|
|
83570
|
+
}
|
|
83571
|
+
}
|
|
83572
|
+
const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
|
|
83573
|
+
const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83574
|
+
narrowedExprType,
|
|
83575
|
+
/*withAlias*/
|
|
83576
|
+
false,
|
|
83577
|
+
node,
|
|
83578
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83579
|
+
) : narrowedExprType;
|
|
83580
|
+
checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
|
|
83581
|
+
}
|
|
83582
|
+
function resetNodeId(node) {
|
|
83583
|
+
node.id = void 0;
|
|
83584
|
+
forEachChildRecursively(node, resetNodeId);
|
|
83585
|
+
}
|
|
83586
|
+
function getNarrowableTypeParameters(candidates) {
|
|
83587
|
+
const narrowableParams = [];
|
|
83588
|
+
for (const typeParam of candidates) {
|
|
83589
|
+
const constraint = getConstraintOfTypeParameter(typeParam);
|
|
83590
|
+
if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
|
|
83591
|
+
if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
|
|
83592
|
+
const declaration = typeParam.symbol.declarations[0];
|
|
83593
|
+
const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
|
|
83594
|
+
if (!isFunctionLike(container)) continue;
|
|
83595
|
+
let paramReference;
|
|
83596
|
+
let referencePath;
|
|
83597
|
+
let hasInvalidReference = false;
|
|
83598
|
+
for (const paramDecl of container.parameters) {
|
|
83599
|
+
const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
|
|
83600
|
+
if (!typeNode) continue;
|
|
83601
|
+
const result = getValidTypeParameterReference(typeNode, typeParam, []);
|
|
83602
|
+
if (!result) {
|
|
83603
|
+
hasInvalidReference = true;
|
|
83604
|
+
break;
|
|
83605
|
+
}
|
|
83606
|
+
if (isArray(result)) {
|
|
83607
|
+
if (referencePath) {
|
|
83608
|
+
hasInvalidReference = true;
|
|
83609
|
+
break;
|
|
83610
|
+
}
|
|
83611
|
+
referencePath = result;
|
|
83612
|
+
paramReference = paramDecl;
|
|
83613
|
+
}
|
|
83614
|
+
}
|
|
83615
|
+
if (!hasInvalidReference && referencePath && validateOptionality(paramReference, constraint, referencePath)) {
|
|
83616
|
+
const symbolAndReference = constructNarrowableReference(paramReference, referencePath);
|
|
83617
|
+
if (symbolAndReference) {
|
|
83618
|
+
if (symbolAndReference[0] && symbolAndReference[0] !== unknownSymbol) {
|
|
83619
|
+
narrowableParams.push([typeParam, symbolAndReference[0], symbolAndReference[1]]);
|
|
83620
|
+
}
|
|
83621
|
+
}
|
|
83622
|
+
}
|
|
83623
|
+
}
|
|
83624
|
+
}
|
|
83625
|
+
return narrowableParams;
|
|
83626
|
+
function isReferenceToTypeParameter(typeParam, node) {
|
|
83627
|
+
return getTypeFromTypeReference(node) === typeParam;
|
|
83628
|
+
}
|
|
83629
|
+
function isTypeParameterReferenced(typeParam, node) {
|
|
83630
|
+
return isReferenced(node);
|
|
83631
|
+
function isReferenced(node2) {
|
|
83632
|
+
if (isTypeReferenceNode(node2)) {
|
|
83633
|
+
return isReferenceToTypeParameter(typeParam, node2) || some(node2.typeArguments, isReferenced);
|
|
83634
|
+
}
|
|
83635
|
+
if (isTypeQueryNode(node2)) {
|
|
83636
|
+
return isTypeParameterPossiblyReferenced(typeParam, node2);
|
|
83637
|
+
}
|
|
83638
|
+
return !!forEachChild(node2, isReferenced);
|
|
83639
|
+
}
|
|
83640
|
+
}
|
|
83641
|
+
function getValidTypeParameterReference(typeNode, typeParam, path) {
|
|
83642
|
+
var _a;
|
|
83643
|
+
switch (typeNode.kind) {
|
|
83644
|
+
case 183 /* TypeReference */:
|
|
83645
|
+
const type = getTypeFromTypeReference(typeNode);
|
|
83646
|
+
if (type === typeParam) {
|
|
83647
|
+
return path;
|
|
83648
|
+
}
|
|
83649
|
+
const typeArgs = typeNode.typeArguments;
|
|
83650
|
+
const typeArgsReferencingT = typeArgs == null ? void 0 : typeArgs.filter((node) => isTypeParameterReferenced(typeParam, node));
|
|
83651
|
+
if (!typeArgsReferencingT || typeArgsReferencingT.length === 0) return true;
|
|
83652
|
+
if (typeArgsReferencingT && typeArgsReferencingT.length > 1) return false;
|
|
83653
|
+
const typeArg = typeArgsReferencingT[0];
|
|
83654
|
+
if (!(typeArg.kind & 183 /* TypeReference */)) return false;
|
|
83655
|
+
if (!type.symbol || !type.symbol.declarations || type.symbol.declarations.length !== 1) return false;
|
|
83656
|
+
const typeDeclaration = type.symbol.declarations[0];
|
|
83657
|
+
let aliasDeclaration;
|
|
83658
|
+
if (isTypeLiteralNode(typeDeclaration)) {
|
|
83659
|
+
aliasDeclaration = walkUpParenthesizedTypes(typeDeclaration.parent);
|
|
83660
|
+
if (!isTypeAliasDeclaration(aliasDeclaration)) return false;
|
|
83661
|
+
} else if (isInterfaceDeclaration(typeDeclaration)) {
|
|
83662
|
+
aliasDeclaration = typeDeclaration;
|
|
83663
|
+
} else {
|
|
83664
|
+
return false;
|
|
83665
|
+
}
|
|
83666
|
+
const typeArgIndex = typeArgs.findIndex((arg) => arg === typeArg);
|
|
83667
|
+
const matchingTypeParamDecl = (_a = aliasDeclaration.typeParameters) == null ? void 0 : _a[typeArgIndex];
|
|
83668
|
+
if (!matchingTypeParamDecl) return false;
|
|
83669
|
+
const matchingTypeParam = getDeclaredTypeOfTypeParameter(matchingTypeParamDecl.symbol);
|
|
83670
|
+
return getValidTypeParameterReference(typeDeclaration, matchingTypeParam, path);
|
|
83671
|
+
case 264 /* InterfaceDeclaration */:
|
|
83672
|
+
const extendsTypes = flatMap(typeNode.heritageClauses, (clause) => clause.types);
|
|
83673
|
+
const relevantExtendsTypes = extendsTypes.filter((node) => isTypeParameterReferenced(typeParam, node));
|
|
83674
|
+
if (relevantExtendsTypes && relevantExtendsTypes.length > 1) {
|
|
83675
|
+
return false;
|
|
83676
|
+
}
|
|
83677
|
+
const result = getValidTypeParameterReferenceFromTypeElements(typeNode.members, typeParam, path);
|
|
83678
|
+
if (relevantExtendsTypes && relevantExtendsTypes.length === 1) {
|
|
83679
|
+
if (result !== true) {
|
|
83680
|
+
return false;
|
|
83681
|
+
}
|
|
83682
|
+
return getValidTypeParameterReference(relevantExtendsTypes[0], typeParam, path);
|
|
83683
|
+
}
|
|
83684
|
+
return result;
|
|
83685
|
+
case 187 /* TypeLiteral */:
|
|
83686
|
+
return getValidTypeParameterReferenceFromTypeElements(typeNode.members, typeParam, path);
|
|
83687
|
+
case 193 /* IntersectionType */:
|
|
83688
|
+
let validPath;
|
|
83689
|
+
for (const type2 of typeNode.types) {
|
|
83690
|
+
const result2 = getValidTypeParameterReference(type2, typeParam, path);
|
|
83691
|
+
if (!result2) {
|
|
83692
|
+
return false;
|
|
83693
|
+
}
|
|
83694
|
+
if (isArray(result2)) {
|
|
83695
|
+
if (validPath) {
|
|
83696
|
+
return false;
|
|
83697
|
+
}
|
|
83698
|
+
validPath = result2;
|
|
83699
|
+
}
|
|
83700
|
+
}
|
|
83701
|
+
return validPath ?? true;
|
|
83702
|
+
default:
|
|
83703
|
+
return !isTypeParameterReferenced(typeParam, typeNode);
|
|
83704
|
+
}
|
|
83705
|
+
}
|
|
83706
|
+
function getValidTypeParameterReferenceFromTypeElements(members, typeParam, path) {
|
|
83707
|
+
let validPath;
|
|
83708
|
+
for (const member of members) {
|
|
83709
|
+
if (!isTypeParameterReferenced(typeParam, member)) {
|
|
83710
|
+
continue;
|
|
83711
|
+
}
|
|
83712
|
+
if (!isPropertySignature(member)) {
|
|
83713
|
+
return false;
|
|
83714
|
+
}
|
|
83715
|
+
if (!isIdentifier(member.name) && !isStringLiteral(member.name)) {
|
|
83716
|
+
return false;
|
|
83717
|
+
}
|
|
83718
|
+
const result = getValidTypeParameterReference(member.type, typeParam, [...path, member]);
|
|
83719
|
+
if (!result) {
|
|
83720
|
+
return false;
|
|
83721
|
+
}
|
|
83722
|
+
if (isArray(result)) {
|
|
83723
|
+
if (validPath) {
|
|
83724
|
+
return false;
|
|
83725
|
+
}
|
|
83726
|
+
validPath = result;
|
|
83727
|
+
}
|
|
83728
|
+
}
|
|
83729
|
+
return validPath ?? true;
|
|
83730
|
+
}
|
|
83731
|
+
function validateOptionality(paramDecl, constraint, path) {
|
|
83732
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
83733
|
+
if (path[i].questionToken) {
|
|
83734
|
+
return false;
|
|
83735
|
+
}
|
|
83736
|
+
}
|
|
83737
|
+
const paramIsOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
|
|
83738
|
+
if (paramIsOptional && path.length > 0) {
|
|
83739
|
+
return false;
|
|
83740
|
+
}
|
|
83741
|
+
const isOptional = paramIsOptional || path.length > 0 && path[path.length - 1].questionToken;
|
|
83742
|
+
if (isOptional && strictNullChecks && !containsUndefinedType(constraint)) {
|
|
83743
|
+
return false;
|
|
83744
|
+
}
|
|
83745
|
+
return true;
|
|
83746
|
+
}
|
|
83747
|
+
function constructNarrowableReference(paramDecl, path) {
|
|
83748
|
+
let currentName = paramDecl.name;
|
|
83749
|
+
let i = 0;
|
|
83750
|
+
for (; i < path.length; i++) {
|
|
83751
|
+
if (isIdentifier(currentName)) {
|
|
83752
|
+
break;
|
|
83753
|
+
} else if (isObjectBindingPattern(currentName)) {
|
|
83754
|
+
const name = path[i].name;
|
|
83755
|
+
let nameText;
|
|
83756
|
+
if (isIdentifier(name)) nameText = name.escapedText;
|
|
83757
|
+
else {
|
|
83758
|
+
const rawText = getLiteralPropertyNameText(name);
|
|
83759
|
+
if (rawText) nameText = escapeLeadingUnderscores(rawText);
|
|
83760
|
+
}
|
|
83761
|
+
const element = currentName.elements.find((element2) => {
|
|
83762
|
+
const propertyName = getDestructuringPropertyName(element2);
|
|
83763
|
+
const propertyNameText = propertyName && escapeLeadingUnderscores(propertyName);
|
|
83764
|
+
return nameText && propertyNameText && nameText === propertyNameText;
|
|
83765
|
+
});
|
|
83766
|
+
if (!element) {
|
|
83767
|
+
return void 0;
|
|
83768
|
+
}
|
|
83769
|
+
currentName = element.name;
|
|
83770
|
+
} else {
|
|
83771
|
+
return void 0;
|
|
83772
|
+
}
|
|
83773
|
+
}
|
|
83774
|
+
if (!isIdentifier(currentName)) {
|
|
83775
|
+
return void 0;
|
|
83776
|
+
}
|
|
83777
|
+
let result = factory.cloneNode(currentName);
|
|
83778
|
+
const initialSymbol = getSymbolOfDeclaration(currentName.parent);
|
|
83779
|
+
for (let j = i; j < path.length; j++) {
|
|
83780
|
+
result = addName(result, path[j].name);
|
|
83781
|
+
}
|
|
83782
|
+
return [initialSymbol, result];
|
|
83783
|
+
}
|
|
83784
|
+
function addName(exp, name) {
|
|
83785
|
+
name = factory.cloneNode(name);
|
|
83786
|
+
if (isIdentifier(name)) {
|
|
83787
|
+
const accessExp = factory.createPropertyAccessExpression(exp, name);
|
|
83788
|
+
setParent(name, accessExp);
|
|
83789
|
+
setParent(exp, accessExp);
|
|
83790
|
+
return accessExp;
|
|
83791
|
+
} else {
|
|
83792
|
+
const accessExp = factory.createElementAccessExpression(exp, name);
|
|
83793
|
+
setParent(name, accessExp);
|
|
83794
|
+
setParent(exp, accessExp);
|
|
83795
|
+
return accessExp;
|
|
83796
|
+
}
|
|
83797
|
+
}
|
|
83798
|
+
}
|
|
83799
|
+
function isNarrowableReturnType(returnType) {
|
|
83800
|
+
return isConditionalType(returnType) ? isNarrowableConditionalType(
|
|
83801
|
+
returnType,
|
|
83802
|
+
/*hadNonPrimitiveExtendsType*/
|
|
83803
|
+
[]
|
|
83804
|
+
) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
|
|
83805
|
+
}
|
|
83806
|
+
function isNarrowableConditionalType(type, hadNonPrimitiveExtendsType, mapper) {
|
|
83807
|
+
const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
|
|
83808
|
+
const mapped = getMappedType(t, mapper);
|
|
83809
|
+
if (isNarrowingSubstitutionType(mapped)) {
|
|
83810
|
+
return mapped.baseType;
|
|
83811
|
+
}
|
|
83812
|
+
return mapped;
|
|
83813
|
+
});
|
|
83814
|
+
const id = `${type.id}:${getTypeListId(typeArguments)}:${getTypeListId(hadNonPrimitiveExtendsType)}`;
|
|
83815
|
+
let result = narrowableReturnTypeCache.get(id);
|
|
83816
|
+
if (result === void 0) {
|
|
83817
|
+
const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
|
|
83818
|
+
const instantiatedType = instantiateType(type, nonNarrowingMapper);
|
|
83819
|
+
result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType, hadNonPrimitiveExtendsType);
|
|
83820
|
+
narrowableReturnTypeCache.set(id, result);
|
|
83821
|
+
}
|
|
83822
|
+
return result;
|
|
83823
|
+
}
|
|
83824
|
+
function isNarrowableConditionalTypeWorker(type, hadNonPrimitiveExtendsType) {
|
|
83825
|
+
if (!type.root.isDistributive) {
|
|
83826
|
+
return false;
|
|
83827
|
+
}
|
|
83828
|
+
if (type.root.inferTypeParameters) {
|
|
83829
|
+
return false;
|
|
83830
|
+
}
|
|
83831
|
+
if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
|
|
83832
|
+
return false;
|
|
83833
|
+
}
|
|
83834
|
+
const constraintType = getConstraintOfTypeParameter(type.checkType);
|
|
83835
|
+
if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
|
|
83836
|
+
return false;
|
|
83837
|
+
}
|
|
83838
|
+
if (!everyType(type.extendsType, (extendsType) => some(
|
|
83839
|
+
constraintType.types,
|
|
83840
|
+
(constraintType2) => isTypeAssignableTo(constraintType2, extendsType)
|
|
83841
|
+
))) {
|
|
83842
|
+
return false;
|
|
83843
|
+
}
|
|
83844
|
+
const hasNonPrimitive = someType(type.extendsType, (type2) => (type2.flags & 402784252 /* Primitive */) === 0);
|
|
83845
|
+
if (hasNonPrimitive && hadNonPrimitiveExtendsType.includes(type.checkType)) {
|
|
83846
|
+
return false;
|
|
83847
|
+
}
|
|
83848
|
+
if (hasNonPrimitive) {
|
|
83849
|
+
hadNonPrimitiveExtendsType = hadNonPrimitiveExtendsType.slice();
|
|
83850
|
+
hadNonPrimitiveExtendsType.push(type.checkType);
|
|
83851
|
+
}
|
|
83852
|
+
const trueType2 = getTrueTypeFromConditionalType(type);
|
|
83853
|
+
const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2, hadNonPrimitiveExtendsType) : true;
|
|
83854
|
+
if (!isValidTrueType) return false;
|
|
83855
|
+
const falseType2 = getFalseTypeFromConditionalType(type);
|
|
83856
|
+
const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2, hadNonPrimitiveExtendsType) : falseType2 === neverType;
|
|
83857
|
+
return isValidFalseType;
|
|
83858
|
+
}
|
|
83859
|
+
function isConditionalType(type) {
|
|
83860
|
+
return !!(type.flags & 16777216 /* Conditional */);
|
|
83417
83861
|
}
|
|
83418
83862
|
function checkWithStatement(node) {
|
|
83419
83863
|
if (!checkGrammarStatementInAmbientContext(node)) {
|
|
@@ -89276,33 +89720,6 @@ function createTypeChecker(host) {
|
|
|
89276
89720
|
Debug.assert(specifier && nodeIsSynthesized(specifier) && specifier.text === "tslib", `Expected sourceFile.imports[0] to be the synthesized tslib import`);
|
|
89277
89721
|
return specifier;
|
|
89278
89722
|
}
|
|
89279
|
-
function compareSymbols(s1, s2) {
|
|
89280
|
-
if (s1 === s2) return 0;
|
|
89281
|
-
if (s1 === void 0) return 1;
|
|
89282
|
-
if (s2 === void 0) return -1;
|
|
89283
|
-
if (length(s1.declarations) !== 0 && length(s2.declarations) !== 0) {
|
|
89284
|
-
const r2 = compareNodes(s1.declarations[0], s2.declarations[0]);
|
|
89285
|
-
if (r2 !== 0) return r2;
|
|
89286
|
-
} else if (length(s1.declarations) !== 0) {
|
|
89287
|
-
return -1;
|
|
89288
|
-
} else if (length(s2.declarations) !== 0) {
|
|
89289
|
-
return 1;
|
|
89290
|
-
}
|
|
89291
|
-
const r = compareComparableValues(s1.escapedName, s2.escapedName);
|
|
89292
|
-
if (r !== 0) return r;
|
|
89293
|
-
return getSymbolId(s1) - getSymbolId(s2);
|
|
89294
|
-
}
|
|
89295
|
-
function compareNodes(n1, n2) {
|
|
89296
|
-
if (n1 === n2) return 0;
|
|
89297
|
-
if (n1 === void 0) return 1;
|
|
89298
|
-
if (n2 === void 0) return -1;
|
|
89299
|
-
const f1 = fileIndexMap.get(getSourceFileOfNode(n1));
|
|
89300
|
-
const f2 = fileIndexMap.get(getSourceFileOfNode(n2));
|
|
89301
|
-
if (f1 !== f2) {
|
|
89302
|
-
return f1 - f2;
|
|
89303
|
-
}
|
|
89304
|
-
return n1.pos - n2.pos;
|
|
89305
|
-
}
|
|
89306
89723
|
}
|
|
89307
89724
|
function isNotAccessor(declaration) {
|
|
89308
89725
|
return !isAccessor(declaration);
|
|
@@ -132244,12 +132661,7 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
132244
132661
|
return withNewScope(context, node, () => serializeTypeAnnotationOfDeclaration(accessorType, context, node, symbol) ?? inferTypeOfDeclaration(node, symbol, context));
|
|
132245
132662
|
}
|
|
132246
132663
|
if (accessorDeclarations.getAccessor) {
|
|
132247
|
-
return withNewScope(context, accessorDeclarations.getAccessor, () => createReturnFromSignature(
|
|
132248
|
-
accessorDeclarations.getAccessor,
|
|
132249
|
-
/*symbol*/
|
|
132250
|
-
void 0,
|
|
132251
|
-
context
|
|
132252
|
-
));
|
|
132664
|
+
return withNewScope(context, accessorDeclarations.getAccessor, () => createReturnFromSignature(accessorDeclarations.getAccessor, symbol, context));
|
|
132253
132665
|
}
|
|
132254
132666
|
return void 0;
|
|
132255
132667
|
}
|
|
@@ -132359,14 +132771,14 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
132359
132771
|
}
|
|
132360
132772
|
return resolver.serializeTypeOfExpression(context, node) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
132361
132773
|
}
|
|
132362
|
-
function inferReturnTypeOfSignatureSignature(node, context, reportFallback) {
|
|
132774
|
+
function inferReturnTypeOfSignatureSignature(node, context, symbol, reportFallback) {
|
|
132363
132775
|
if (reportFallback) {
|
|
132364
132776
|
context.tracker.reportInferenceFallback(node);
|
|
132365
132777
|
}
|
|
132366
132778
|
if (context.noInferenceFallback === true) {
|
|
132367
132779
|
return factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
132368
132780
|
}
|
|
132369
|
-
return resolver.serializeReturnTypeForSignature(context, node) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
132781
|
+
return resolver.serializeReturnTypeForSignature(context, node, symbol) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
132370
132782
|
}
|
|
132371
132783
|
function inferAccessorType(node, allAccessors, context, symbol, reportFallback = true) {
|
|
132372
132784
|
if (node.kind === 177 /* GetAccessor */) {
|
|
@@ -132801,7 +133213,7 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
132801
133213
|
} else if (isValueSignatureDeclaration(fn)) {
|
|
132802
133214
|
returnType = typeFromSingleReturnExpression(fn, context);
|
|
132803
133215
|
}
|
|
132804
|
-
return returnType.type !== void 0 ? returnType.type : inferReturnTypeOfSignatureSignature(fn, context, reportFallback && returnType.reportFallback && !returnTypeNode);
|
|
133216
|
+
return returnType.type !== void 0 ? returnType.type : inferReturnTypeOfSignatureSignature(fn, context, symbol, reportFallback && returnType.reportFallback && !returnTypeNode);
|
|
132805
133217
|
}
|
|
132806
133218
|
function typeFromSingleReturnExpression(declaration, context) {
|
|
132807
133219
|
let candidateExpr;
|