@typescript-deploys/pr-build 5.9.0-pr-61359-4 → 5.9.0-pr-61505-16
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 +64 -480
- package/lib/typescript.js +71 -481
- package/package.json +1 -1
package/lib/_tsc.js
CHANGED
|
@@ -18,11 +18,15 @@ 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.20250401`;
|
|
22
22
|
|
|
23
23
|
// src/compiler/core.ts
|
|
24
24
|
var emptyArray = [];
|
|
25
25
|
var emptyMap = /* @__PURE__ */ new Map();
|
|
26
|
+
var voidMap = /* @__PURE__ */ new Map();
|
|
27
|
+
voidMap.set = function() {
|
|
28
|
+
return this;
|
|
29
|
+
};
|
|
26
30
|
function length(array) {
|
|
27
31
|
return array !== void 0 ? array.length : 0;
|
|
28
32
|
}
|
|
@@ -3680,7 +3684,6 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
|
|
|
3680
3684
|
ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
|
|
3681
3685
|
ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
|
|
3682
3686
|
ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
|
|
3683
|
-
ObjectFlags3[ObjectFlags3["IsNarrowingType"] = 16777216] = "IsNarrowingType";
|
|
3684
3687
|
ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
|
|
3685
3688
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
|
|
3686
3689
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
|
|
@@ -46819,6 +46822,7 @@ function createTypeChecker(host) {
|
|
|
46819
46822
|
var templateConstraintType = getUnionType([stringType, numberType, booleanType, bigintType, nullType, undefinedType]);
|
|
46820
46823
|
var numericStringType = getTemplateLiteralType(["", ""], [numberType]);
|
|
46821
46824
|
var restrictiveMapper = makeFunctionTypeMapper((t) => t.flags & 262144 /* TypeParameter */ ? getRestrictiveTypeParameter(t) : t, () => "(restrictive mapper)");
|
|
46825
|
+
restrictiveMapper.instantiations = voidMap;
|
|
46822
46826
|
var permissiveMapper = makeFunctionTypeMapper((t) => t.flags & 262144 /* TypeParameter */ ? wildcardType : t, () => "(permissive mapper)");
|
|
46823
46827
|
var uniqueLiteralType = createIntrinsicType(
|
|
46824
46828
|
131072 /* Never */,
|
|
@@ -46838,6 +46842,7 @@ function createTypeChecker(host) {
|
|
|
46838
46842
|
}
|
|
46839
46843
|
return t;
|
|
46840
46844
|
}, () => "(unmeasurable reporter)");
|
|
46845
|
+
reportUnreliableMapper.instantiations = voidMap;
|
|
46841
46846
|
var reportUnmeasurableMapper = makeFunctionTypeMapper((t) => {
|
|
46842
46847
|
if (outofbandVarianceMarkerHandler && (t === markerSuperType || t === markerSubType || t === markerOtherType)) {
|
|
46843
46848
|
outofbandVarianceMarkerHandler(
|
|
@@ -46847,6 +46852,7 @@ function createTypeChecker(host) {
|
|
|
46847
46852
|
}
|
|
46848
46853
|
return t;
|
|
46849
46854
|
}, () => "(unreliable reporter)");
|
|
46855
|
+
reportUnmeasurableMapper.instantiations = voidMap;
|
|
46850
46856
|
var emptyObjectType = createAnonymousType(
|
|
46851
46857
|
/*symbol*/
|
|
46852
46858
|
void 0,
|
|
@@ -47179,7 +47185,6 @@ function createTypeChecker(host) {
|
|
|
47179
47185
|
[".jsx", ".jsx"],
|
|
47180
47186
|
[".json", ".json"]
|
|
47181
47187
|
];
|
|
47182
|
-
var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
|
|
47183
47188
|
initializeTypeChecker();
|
|
47184
47189
|
return checker;
|
|
47185
47190
|
function isDefinitelyReferenceToGlobalSymbolObject(node) {
|
|
@@ -59443,14 +59448,11 @@ function createTypeChecker(host) {
|
|
|
59443
59448
|
function isNoInferType(type) {
|
|
59444
59449
|
return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
|
|
59445
59450
|
}
|
|
59446
|
-
function
|
|
59447
|
-
return
|
|
59448
|
-
}
|
|
59449
|
-
function getSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59450
|
-
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
|
|
59451
|
+
function getSubstitutionType(baseType, constraint) {
|
|
59452
|
+
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint);
|
|
59451
59453
|
}
|
|
59452
|
-
function getOrCreateSubstitutionType(baseType, constraint
|
|
59453
|
-
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}
|
|
59454
|
+
function getOrCreateSubstitutionType(baseType, constraint) {
|
|
59455
|
+
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
|
|
59454
59456
|
const cached = substitutionTypes.get(id);
|
|
59455
59457
|
if (cached) {
|
|
59456
59458
|
return cached;
|
|
@@ -59458,9 +59460,6 @@ function createTypeChecker(host) {
|
|
|
59458
59460
|
const result = createType(33554432 /* Substitution */);
|
|
59459
59461
|
result.baseType = baseType;
|
|
59460
59462
|
result.constraint = constraint;
|
|
59461
|
-
if (isNarrowed) {
|
|
59462
|
-
result.objectFlags |= 16777216 /* IsNarrowingType */;
|
|
59463
|
-
}
|
|
59464
59463
|
substitutionTypes.set(id, result);
|
|
59465
59464
|
return result;
|
|
59466
59465
|
}
|
|
@@ -61666,7 +61665,7 @@ function createTypeChecker(host) {
|
|
|
61666
61665
|
function isDeferredType(type, checkTuples) {
|
|
61667
61666
|
return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
|
|
61668
61667
|
}
|
|
61669
|
-
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments
|
|
61668
|
+
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
|
|
61670
61669
|
let result;
|
|
61671
61670
|
let extraTypes;
|
|
61672
61671
|
let tailCount = 0;
|
|
@@ -61683,11 +61682,10 @@ function createTypeChecker(host) {
|
|
|
61683
61682
|
if (checkType === wildcardType || extendsType === wildcardType) {
|
|
61684
61683
|
return wildcardType;
|
|
61685
61684
|
}
|
|
61686
|
-
const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
|
|
61687
61685
|
const checkTypeNode = skipTypeParentheses(root.node.checkType);
|
|
61688
61686
|
const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
|
|
61689
61687
|
const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
|
|
61690
|
-
const checkTypeDeferred = isDeferredType(
|
|
61688
|
+
const checkTypeDeferred = isDeferredType(checkType, checkTuples);
|
|
61691
61689
|
let combinedMapper;
|
|
61692
61690
|
if (root.inferTypeParameters) {
|
|
61693
61691
|
const context = createInferenceContext(
|
|
@@ -61700,14 +61698,14 @@ function createTypeChecker(host) {
|
|
|
61700
61698
|
context.nonFixingMapper = combineTypeMappers(context.nonFixingMapper, mapper);
|
|
61701
61699
|
}
|
|
61702
61700
|
if (!checkTypeDeferred) {
|
|
61703
|
-
inferTypes(context.inferences, checkType, extendsType, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
61701
|
+
inferTypes(context, context.inferences, checkType, extendsType, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
61704
61702
|
}
|
|
61705
61703
|
combinedMapper = mapper ? combineTypeMappers(context.mapper, mapper) : context.mapper;
|
|
61706
61704
|
}
|
|
61707
61705
|
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
|
|
61708
61706
|
if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
|
|
61709
|
-
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (
|
|
61710
|
-
if (
|
|
61707
|
+
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (checkType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
|
|
61708
|
+
if (checkType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(checkType)))) {
|
|
61711
61709
|
(extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
|
|
61712
61710
|
}
|
|
61713
61711
|
const falseType2 = getTypeFromTypeNode(root.node.falseType);
|
|
@@ -61724,7 +61722,7 @@ function createTypeChecker(host) {
|
|
|
61724
61722
|
result = instantiateType(falseType2, mapper);
|
|
61725
61723
|
break;
|
|
61726
61724
|
}
|
|
61727
|
-
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(
|
|
61725
|
+
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
|
|
61728
61726
|
const trueType2 = getTypeFromTypeNode(root.node.trueType);
|
|
61729
61727
|
const trueMapper = combinedMapper || mapper;
|
|
61730
61728
|
if (canTailRecurse(trueType2, trueMapper)) {
|
|
@@ -62690,44 +62688,8 @@ function createTypeChecker(host) {
|
|
|
62690
62688
|
if (!result) {
|
|
62691
62689
|
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
|
|
62692
62690
|
const checkType = root.checkType;
|
|
62693
|
-
|
|
62694
|
-
|
|
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
|
-
}
|
|
62691
|
+
const distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
|
|
62692
|
+
result = distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments) : getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments);
|
|
62731
62693
|
root.instantiations.set(id, result);
|
|
62732
62694
|
}
|
|
62733
62695
|
return result;
|
|
@@ -62745,7 +62707,7 @@ function createTypeChecker(host) {
|
|
|
62745
62707
|
) : type;
|
|
62746
62708
|
}
|
|
62747
62709
|
function instantiateTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
|
|
62748
|
-
var _a;
|
|
62710
|
+
var _a, _b;
|
|
62749
62711
|
if (!couldContainTypeVariables(type)) {
|
|
62750
62712
|
return type;
|
|
62751
62713
|
}
|
|
@@ -62754,10 +62716,16 @@ function createTypeChecker(host) {
|
|
|
62754
62716
|
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
|
|
62755
62717
|
return errorType;
|
|
62756
62718
|
}
|
|
62719
|
+
const key = type.id + getAliasId(aliasSymbol, aliasTypeArguments);
|
|
62720
|
+
const cached = (mapper.instantiations ?? (mapper.instantiations = /* @__PURE__ */ new Map())).get(key);
|
|
62721
|
+
if (cached) {
|
|
62722
|
+
return cached;
|
|
62723
|
+
}
|
|
62757
62724
|
totalInstantiationCount++;
|
|
62758
62725
|
instantiationCount++;
|
|
62759
62726
|
instantiationDepth++;
|
|
62760
62727
|
const result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments);
|
|
62728
|
+
(_b = mapper.instantiations) == null ? void 0 : _b.set(key, result);
|
|
62761
62729
|
instantiationDepth--;
|
|
62762
62730
|
return result;
|
|
62763
62731
|
}
|
|
@@ -63870,12 +63838,10 @@ function createTypeChecker(host) {
|
|
|
63870
63838
|
function shouldNormalizeIntersection(type) {
|
|
63871
63839
|
let hasInstantiable = false;
|
|
63872
63840
|
let hasNullableOrEmpty = false;
|
|
63873
|
-
let hasSubstitution = false;
|
|
63874
63841
|
for (const t of type.types) {
|
|
63875
63842
|
hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
|
|
63876
63843
|
hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
|
|
63877
|
-
|
|
63878
|
-
if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
|
|
63844
|
+
if (hasInstantiable && hasNullableOrEmpty) return true;
|
|
63879
63845
|
}
|
|
63880
63846
|
return false;
|
|
63881
63847
|
}
|
|
@@ -65382,7 +65348,7 @@ function createTypeChecker(host) {
|
|
|
65382
65348
|
0 /* None */,
|
|
65383
65349
|
isRelatedToWorker
|
|
65384
65350
|
);
|
|
65385
|
-
inferTypes(ctx.inferences, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
65351
|
+
inferTypes(ctx, ctx.inferences, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
|
|
65386
65352
|
sourceExtends = instantiateType(sourceExtends, ctx.mapper);
|
|
65387
65353
|
mapper = ctx.mapper;
|
|
65388
65354
|
}
|
|
@@ -67262,7 +67228,7 @@ function createTypeChecker(host) {
|
|
|
67262
67228
|
map(context.inferences, (inference, i) => () => {
|
|
67263
67229
|
if (!inference.isFixed) {
|
|
67264
67230
|
inferFromIntraExpressionSites(context);
|
|
67265
|
-
clearCachedInferences(context.inferences);
|
|
67231
|
+
clearCachedInferences(context, context.inferences);
|
|
67266
67232
|
inference.isFixed = true;
|
|
67267
67233
|
}
|
|
67268
67234
|
return getInferredType(context, i);
|
|
@@ -67277,7 +67243,10 @@ function createTypeChecker(host) {
|
|
|
67277
67243
|
})
|
|
67278
67244
|
);
|
|
67279
67245
|
}
|
|
67280
|
-
function clearCachedInferences(inferences) {
|
|
67246
|
+
function clearCachedInferences(context, inferences) {
|
|
67247
|
+
if (context) {
|
|
67248
|
+
context.nonFixingMapper.instantiations = void 0;
|
|
67249
|
+
}
|
|
67281
67250
|
for (const inference of inferences) {
|
|
67282
67251
|
if (!inference.isFixed) {
|
|
67283
67252
|
inference.inferredType = void 0;
|
|
@@ -67292,7 +67261,7 @@ function createTypeChecker(host) {
|
|
|
67292
67261
|
for (const { node, type } of context.intraExpressionInferenceSites) {
|
|
67293
67262
|
const contextualType = node.kind === 174 /* MethodDeclaration */ ? getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) : getContextualType(node, 2 /* NoConstraints */);
|
|
67294
67263
|
if (contextualType) {
|
|
67295
|
-
inferTypes(context.inferences, type, contextualType);
|
|
67264
|
+
inferTypes(context, context.inferences, type, contextualType);
|
|
67296
67265
|
}
|
|
67297
67266
|
}
|
|
67298
67267
|
context.intraExpressionInferenceSites = void 0;
|
|
@@ -67436,7 +67405,13 @@ function createTypeChecker(host) {
|
|
|
67436
67405
|
const typeParameter = getIndexedAccessType(constraint.type, getTypeParameterFromMappedType(target));
|
|
67437
67406
|
const templateType = getTemplateTypeFromMappedType(target);
|
|
67438
67407
|
const inference = createInferenceInfo(typeParameter);
|
|
67439
|
-
inferTypes(
|
|
67408
|
+
inferTypes(
|
|
67409
|
+
/*context*/
|
|
67410
|
+
void 0,
|
|
67411
|
+
[inference],
|
|
67412
|
+
sourceType,
|
|
67413
|
+
templateType
|
|
67414
|
+
);
|
|
67440
67415
|
return getTypeFromInference(inference) || unknownType;
|
|
67441
67416
|
}
|
|
67442
67417
|
function inferReverseMappedType(source, target, constraint) {
|
|
@@ -67638,7 +67613,7 @@ function createTypeChecker(host) {
|
|
|
67638
67613
|
function isTupleOfSelf(typeParameter, type) {
|
|
67639
67614
|
return isTupleType(type) && getTupleElementType(type, 0) === getIndexedAccessType(typeParameter, getNumberLiteralType(0)) && !getTypeOfPropertyOfType(type, "1");
|
|
67640
67615
|
}
|
|
67641
|
-
function inferTypes(inferences, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
|
|
67616
|
+
function inferTypes(context, inferences, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
|
|
67642
67617
|
let bivariant = false;
|
|
67643
67618
|
let propagationType;
|
|
67644
67619
|
let inferencePriority = 2048 /* MaxValue */;
|
|
@@ -67729,16 +67704,16 @@ function createTypeChecker(host) {
|
|
|
67729
67704
|
if (contravariant && !bivariant) {
|
|
67730
67705
|
if (!contains(inference.contraCandidates, candidate)) {
|
|
67731
67706
|
inference.contraCandidates = append(inference.contraCandidates, candidate);
|
|
67732
|
-
clearCachedInferences(inferences);
|
|
67707
|
+
clearCachedInferences(context, inferences);
|
|
67733
67708
|
}
|
|
67734
67709
|
} else if (!contains(inference.candidates, candidate)) {
|
|
67735
67710
|
inference.candidates = append(inference.candidates, candidate);
|
|
67736
|
-
clearCachedInferences(inferences);
|
|
67711
|
+
clearCachedInferences(context, inferences);
|
|
67737
67712
|
}
|
|
67738
67713
|
}
|
|
67739
67714
|
if (!(priority & 128 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
|
|
67740
67715
|
inference.topLevel = false;
|
|
67741
|
-
clearCachedInferences(inferences);
|
|
67716
|
+
clearCachedInferences(context, inferences);
|
|
67742
67717
|
}
|
|
67743
67718
|
}
|
|
67744
67719
|
inferencePriority = Math.min(inferencePriority, priority);
|
|
@@ -68304,6 +68279,7 @@ function createTypeChecker(host) {
|
|
|
68304
68279
|
const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
|
|
68305
68280
|
if (!inferredType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
|
|
68306
68281
|
inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint;
|
|
68282
|
+
context.nonFixingMapper.instantiations = void 0;
|
|
68307
68283
|
}
|
|
68308
68284
|
}
|
|
68309
68285
|
}
|
|
@@ -69035,18 +69011,6 @@ function createTypeChecker(host) {
|
|
|
69035
69011
|
}
|
|
69036
69012
|
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
|
|
69037
69013
|
}
|
|
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
|
-
}
|
|
69050
69014
|
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
|
|
69051
69015
|
return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
|
|
69052
69016
|
}
|
|
@@ -70631,11 +70595,11 @@ function createTypeChecker(host) {
|
|
|
70631
70595
|
));
|
|
70632
70596
|
return contextualType && !isGenericType(contextualType);
|
|
70633
70597
|
}
|
|
70634
|
-
function getNarrowableTypeForReference(type, reference, checkMode
|
|
70598
|
+
function getNarrowableTypeForReference(type, reference, checkMode) {
|
|
70635
70599
|
if (isNoInferType(type)) {
|
|
70636
70600
|
type = type.baseType;
|
|
70637
70601
|
}
|
|
70638
|
-
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (
|
|
70602
|
+
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70639
70603
|
return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
|
|
70640
70604
|
}
|
|
70641
70605
|
function isExportOrExportExpression(location) {
|
|
@@ -71762,16 +71726,9 @@ function createTypeChecker(host) {
|
|
|
71762
71726
|
function getContextualTypeForReturnExpression(node, contextFlags) {
|
|
71763
71727
|
const func = getContainingFunction(node);
|
|
71764
71728
|
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
|
-
}
|
|
71773
71729
|
let contextualReturnType = getContextualReturnType(func, contextFlags);
|
|
71774
71730
|
if (contextualReturnType) {
|
|
71731
|
+
const functionFlags = getFunctionFlags(func);
|
|
71775
71732
|
if (functionFlags & 1 /* Generator */) {
|
|
71776
71733
|
const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
|
|
71777
71734
|
if (contextualReturnType.flags & 1048576 /* Union */) {
|
|
@@ -72469,13 +72426,6 @@ function createTypeChecker(host) {
|
|
|
72469
72426
|
if (index >= 0) {
|
|
72470
72427
|
return contextualTypes[index];
|
|
72471
72428
|
}
|
|
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
|
-
}
|
|
72479
72429
|
const { parent } = node;
|
|
72480
72430
|
switch (parent.kind) {
|
|
72481
72431
|
case 260 /* VariableDeclaration */:
|
|
@@ -74457,7 +74407,7 @@ function createTypeChecker(host) {
|
|
|
74457
74407
|
addErrorOrSuggestion(!isUncheckedJS || errorInfo.code !== Diagnostics.Property_0_may_not_exist_on_type_1_Did_you_mean_2.code, resultDiagnostic);
|
|
74458
74408
|
}
|
|
74459
74409
|
function containerSeemsToBeEmptyDomElement(containingType) {
|
|
74460
|
-
return compilerOptions.lib && !compilerOptions.lib.includes("dom") && everyContainedType(containingType, (type) => type.symbol && /^(?:EventTarget|Node|(?:HTML[a-zA-Z]*)?Element)$/.test(unescapeLeadingUnderscores(type.symbol.escapedName))) && isEmptyObjectType(containingType);
|
|
74410
|
+
return compilerOptions.lib && !compilerOptions.lib.includes("lib.dom.d.ts") && everyContainedType(containingType, (type) => type.symbol && /^(?:EventTarget|Node|(?:HTML[a-zA-Z]*)?Element)$/.test(unescapeLeadingUnderscores(type.symbol.escapedName))) && isEmptyObjectType(containingType);
|
|
74461
74411
|
}
|
|
74462
74412
|
function typeHasStaticProperty(propName, containingType) {
|
|
74463
74413
|
const prop = containingType.symbol && getPropertyOfType(getTypeOfSymbol(containingType.symbol), propName);
|
|
@@ -74904,11 +74854,11 @@ function createTypeChecker(host) {
|
|
|
74904
74854
|
const mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
|
|
74905
74855
|
const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
|
|
74906
74856
|
applyToParameterTypes(sourceSignature, signature, (source, target) => {
|
|
74907
|
-
inferTypes(context.inferences, source, target);
|
|
74857
|
+
inferTypes(context, context.inferences, source, target);
|
|
74908
74858
|
});
|
|
74909
74859
|
if (!inferenceContext) {
|
|
74910
74860
|
applyToReturnTypes(contextualSignature, signature, (source, target) => {
|
|
74911
|
-
inferTypes(context.inferences, source, target, 128 /* ReturnType */);
|
|
74861
|
+
inferTypes(context, context.inferences, source, target, 128 /* ReturnType */);
|
|
74912
74862
|
});
|
|
74913
74863
|
}
|
|
74914
74864
|
return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
|
|
@@ -74916,7 +74866,7 @@ function createTypeChecker(host) {
|
|
|
74916
74866
|
function inferJsxTypeArguments(node, signature, checkMode, context) {
|
|
74917
74867
|
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
|
|
74918
74868
|
const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode);
|
|
74919
|
-
inferTypes(context.inferences, checkAttrType, paramType);
|
|
74869
|
+
inferTypes(context, context.inferences, checkAttrType, paramType);
|
|
74920
74870
|
return getInferredTypes(context);
|
|
74921
74871
|
}
|
|
74922
74872
|
function getThisArgumentType(thisArgumentNode) {
|
|
@@ -74943,11 +74893,11 @@ function createTypeChecker(host) {
|
|
|
74943
74893
|
const instantiatedType = instantiateType(contextualType, outerMapper);
|
|
74944
74894
|
const contextualSignature = getSingleCallSignature(instantiatedType);
|
|
74945
74895
|
const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : instantiatedType;
|
|
74946
|
-
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
|
|
74896
|
+
inferTypes(context, context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
|
|
74947
74897
|
}
|
|
74948
74898
|
const returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
|
|
74949
74899
|
const returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
|
|
74950
|
-
inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
|
|
74900
|
+
inferTypes(returnContext, returnContext.inferences, returnSourceType, inferenceTargetType);
|
|
74951
74901
|
context.returnMapper = some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : void 0;
|
|
74952
74902
|
}
|
|
74953
74903
|
}
|
|
@@ -74963,7 +74913,7 @@ function createTypeChecker(host) {
|
|
|
74963
74913
|
const thisType = getThisTypeOfSignature(signature);
|
|
74964
74914
|
if (thisType && couldContainTypeVariables(thisType)) {
|
|
74965
74915
|
const thisArgumentNode = getThisArgumentOfCall(node);
|
|
74966
|
-
inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
|
|
74916
|
+
inferTypes(context, context.inferences, getThisArgumentType(thisArgumentNode), thisType);
|
|
74967
74917
|
}
|
|
74968
74918
|
for (let i = 0; i < argCount; i++) {
|
|
74969
74919
|
const arg = args[i];
|
|
@@ -74971,13 +74921,13 @@ function createTypeChecker(host) {
|
|
|
74971
74921
|
const paramType = getTypeAtPosition(signature, i);
|
|
74972
74922
|
if (couldContainTypeVariables(paramType)) {
|
|
74973
74923
|
const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
|
|
74974
|
-
inferTypes(context.inferences, argType, paramType);
|
|
74924
|
+
inferTypes(context, context.inferences, argType, paramType);
|
|
74975
74925
|
}
|
|
74976
74926
|
}
|
|
74977
74927
|
}
|
|
74978
74928
|
if (restType && couldContainTypeVariables(restType)) {
|
|
74979
74929
|
const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
|
|
74980
|
-
inferTypes(context.inferences, spreadType, restType);
|
|
74930
|
+
inferTypes(context, context.inferences, spreadType, restType);
|
|
74981
74931
|
}
|
|
74982
74932
|
return getInferredTypes(context);
|
|
74983
74933
|
}
|
|
@@ -77350,14 +77300,14 @@ function createTypeChecker(host) {
|
|
|
77350
77300
|
isOptionalDeclaration(declaration)
|
|
77351
77301
|
);
|
|
77352
77302
|
const target = getTypeAtPosition(context, i);
|
|
77353
|
-
inferTypes(inferenceContext.inferences, source, target);
|
|
77303
|
+
inferTypes(inferenceContext, inferenceContext.inferences, source, target);
|
|
77354
77304
|
}
|
|
77355
77305
|
}
|
|
77356
77306
|
const typeNode = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
|
|
77357
77307
|
if (typeNode) {
|
|
77358
77308
|
const source = getTypeFromTypeNode(typeNode);
|
|
77359
77309
|
const target = getReturnTypeOfSignature(context);
|
|
77360
|
-
inferTypes(inferenceContext.inferences, source, target);
|
|
77310
|
+
inferTypes(inferenceContext, inferenceContext.inferences, source, target);
|
|
77361
77311
|
}
|
|
77362
77312
|
}
|
|
77363
77313
|
function assignContextualParameterTypes(signature, context) {
|
|
@@ -79773,6 +79723,7 @@ function createTypeChecker(host) {
|
|
|
79773
79723
|
const inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
|
|
79774
79724
|
applyToParameterTypes(instantiatedSignature, contextualSignature, (source, target) => {
|
|
79775
79725
|
inferTypes(
|
|
79726
|
+
context,
|
|
79776
79727
|
inferences,
|
|
79777
79728
|
source,
|
|
79778
79729
|
target,
|
|
@@ -79784,7 +79735,7 @@ function createTypeChecker(host) {
|
|
|
79784
79735
|
});
|
|
79785
79736
|
if (some(inferences, hasInferenceCandidates)) {
|
|
79786
79737
|
applyToReturnTypes(instantiatedSignature, contextualSignature, (source, target) => {
|
|
79787
|
-
inferTypes(inferences, source, target);
|
|
79738
|
+
inferTypes(context, inferences, source, target);
|
|
79788
79739
|
});
|
|
79789
79740
|
if (!hasOverlappingInferences(context.inferences, inferences)) {
|
|
79790
79741
|
mergeInferences(context.inferences, inferences);
|
|
@@ -83490,374 +83441,7 @@ function createTypeChecker(host) {
|
|
|
83490
83441
|
) : exprType;
|
|
83491
83442
|
const effectiveExpr = expr && getEffectiveCheckNode(expr);
|
|
83492
83443
|
const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
|
|
83493
|
-
|
|
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 */);
|
|
83444
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83861
83445
|
}
|
|
83862
83446
|
function checkWithStatement(node) {
|
|
83863
83447
|
if (!checkGrammarStatementInAmbientContext(node)) {
|