typescript 5.7.0-dev.20241105 → 5.8.0-dev.20241107
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 +547 -103
- package/lib/_tsserver.js +43 -7
- package/lib/lib.esnext.d.ts +1 -0
- package/lib/lib.esnext.promise.d.ts +34 -0
- package/lib/typescript.d.ts +13 -3
- package/lib/typescript.js +626 -120
- package/package.json +2 -2
- package/lib/cancellationToken.js +0 -90
package/lib/typescript.js
CHANGED
@@ -2277,8 +2277,8 @@ __export(typescript_exports, {
|
|
2277
2277
|
module.exports = __toCommonJS(typescript_exports);
|
2278
2278
|
|
2279
2279
|
// src/compiler/corePublic.ts
|
2280
|
-
var versionMajorMinor = "5.
|
2281
|
-
var version = `${versionMajorMinor}.0-dev.
|
2280
|
+
var versionMajorMinor = "5.8";
|
2281
|
+
var version = `${versionMajorMinor}.0-dev.20241107`;
|
2282
2282
|
var Comparison = /* @__PURE__ */ ((Comparison3) => {
|
2283
2283
|
Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
|
2284
2284
|
Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
|
@@ -6531,6 +6531,7 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
|
|
6531
6531
|
ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
|
6532
6532
|
ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
|
6533
6533
|
ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
|
6534
|
+
ObjectFlags3[ObjectFlags3["IsNarrowingType"] = 16777216] = "IsNarrowingType";
|
6534
6535
|
ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
|
6535
6536
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
|
6536
6537
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
|
@@ -7141,8 +7142,9 @@ var OuterExpressionKinds = /* @__PURE__ */ ((OuterExpressionKinds2) => {
|
|
7141
7142
|
OuterExpressionKinds2[OuterExpressionKinds2["NonNullAssertions"] = 4] = "NonNullAssertions";
|
7142
7143
|
OuterExpressionKinds2[OuterExpressionKinds2["PartiallyEmittedExpressions"] = 8] = "PartiallyEmittedExpressions";
|
7143
7144
|
OuterExpressionKinds2[OuterExpressionKinds2["ExpressionsWithTypeArguments"] = 16] = "ExpressionsWithTypeArguments";
|
7144
|
-
OuterExpressionKinds2[OuterExpressionKinds2["
|
7145
|
-
OuterExpressionKinds2[OuterExpressionKinds2["
|
7145
|
+
OuterExpressionKinds2[OuterExpressionKinds2["Satisfies"] = 32] = "Satisfies";
|
7146
|
+
OuterExpressionKinds2[OuterExpressionKinds2["Assertions"] = 38] = "Assertions";
|
7147
|
+
OuterExpressionKinds2[OuterExpressionKinds2["All"] = 63] = "All";
|
7146
7148
|
OuterExpressionKinds2[OuterExpressionKinds2["ExcludeJSDocTypeAssertion"] = -2147483648] = "ExcludeJSDocTypeAssertion";
|
7147
7149
|
return OuterExpressionKinds2;
|
7148
7150
|
})(OuterExpressionKinds || {});
|
@@ -18774,7 +18776,7 @@ function tryGetImportFromModuleSpecifier(node) {
|
|
18774
18776
|
}
|
18775
18777
|
}
|
18776
18778
|
function shouldRewriteModuleSpecifier(specifier, compilerOptions) {
|
18777
|
-
return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier);
|
18779
|
+
return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier) && hasTSFileExtension(specifier);
|
18778
18780
|
}
|
18779
18781
|
function getExternalModuleName(node) {
|
18780
18782
|
switch (node.kind) {
|
@@ -26552,6 +26554,8 @@ function createNodeFactory(flags, baseFactory2) {
|
|
26552
26554
|
node.colonToken = colonToken ?? createToken(59 /* ColonToken */);
|
26553
26555
|
node.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse);
|
26554
26556
|
node.transformFlags |= propagateChildFlags(node.condition) | propagateChildFlags(node.questionToken) | propagateChildFlags(node.whenTrue) | propagateChildFlags(node.colonToken) | propagateChildFlags(node.whenFalse);
|
26557
|
+
node.flowNodeWhenFalse = void 0;
|
26558
|
+
node.flowNodeWhenTrue = void 0;
|
26555
26559
|
return node;
|
26556
26560
|
}
|
26557
26561
|
function updateConditionalExpression(node, condition, questionToken, whenTrue, colonToken, whenFalse) {
|
@@ -28355,7 +28359,7 @@ function createNodeFactory(flags, baseFactory2) {
|
|
28355
28359
|
function isIgnorableParen(node) {
|
28356
28360
|
return isParenthesizedExpression(node) && nodeIsSynthesized(node) && nodeIsSynthesized(getSourceMapRange(node)) && nodeIsSynthesized(getCommentRange(node)) && !some(getSyntheticLeadingComments(node)) && !some(getSyntheticTrailingComments(node));
|
28357
28361
|
}
|
28358
|
-
function restoreOuterExpressions(outerExpression, innerExpression, kinds =
|
28362
|
+
function restoreOuterExpressions(outerExpression, innerExpression, kinds = 63 /* All */) {
|
28359
28363
|
if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
|
28360
28364
|
return updateOuterExpression(
|
28361
28365
|
outerExpression,
|
@@ -28401,7 +28405,7 @@ function createNodeFactory(flags, baseFactory2) {
|
|
28401
28405
|
}
|
28402
28406
|
}
|
28403
28407
|
function createCallBinding(expression, recordTempVariable, languageVersion, cacheIdentifiers = false) {
|
28404
|
-
const callee = skipOuterExpressions(expression,
|
28408
|
+
const callee = skipOuterExpressions(expression, 63 /* All */);
|
28405
28409
|
let thisArg;
|
28406
28410
|
let target;
|
28407
28411
|
if (isSuperProperty(callee)) {
|
@@ -31404,7 +31408,7 @@ function getJSDocTypeAssertionType(node) {
|
|
31404
31408
|
Debug.assertIsDefined(type);
|
31405
31409
|
return type;
|
31406
31410
|
}
|
31407
|
-
function isOuterExpression(node, kinds =
|
31411
|
+
function isOuterExpression(node, kinds = 63 /* All */) {
|
31408
31412
|
switch (node.kind) {
|
31409
31413
|
case 217 /* ParenthesizedExpression */:
|
31410
31414
|
if (kinds & -2147483648 /* ExcludeJSDocTypeAssertion */ && isJSDocTypeAssertion(node)) {
|
@@ -31413,8 +31417,9 @@ function isOuterExpression(node, kinds = 31 /* All */) {
|
|
31413
31417
|
return (kinds & 1 /* Parentheses */) !== 0;
|
31414
31418
|
case 216 /* TypeAssertionExpression */:
|
31415
31419
|
case 234 /* AsExpression */:
|
31416
|
-
case 238 /* SatisfiesExpression */:
|
31417
31420
|
return (kinds & 2 /* TypeAssertions */) !== 0;
|
31421
|
+
case 238 /* SatisfiesExpression */:
|
31422
|
+
return (kinds & (2 /* TypeAssertions */ | 32 /* Satisfies */)) !== 0;
|
31418
31423
|
case 233 /* ExpressionWithTypeArguments */:
|
31419
31424
|
return (kinds & 16 /* ExpressionsWithTypeArguments */) !== 0;
|
31420
31425
|
case 235 /* NonNullExpression */:
|
@@ -31424,13 +31429,13 @@ function isOuterExpression(node, kinds = 31 /* All */) {
|
|
31424
31429
|
}
|
31425
31430
|
return false;
|
31426
31431
|
}
|
31427
|
-
function skipOuterExpressions(node, kinds =
|
31432
|
+
function skipOuterExpressions(node, kinds = 63 /* All */) {
|
31428
31433
|
while (isOuterExpression(node, kinds)) {
|
31429
31434
|
node = node.expression;
|
31430
31435
|
}
|
31431
31436
|
return node;
|
31432
31437
|
}
|
31433
|
-
function walkUpOuterExpressions(node, kinds =
|
31438
|
+
function walkUpOuterExpressions(node, kinds = 63 /* All */) {
|
31434
31439
|
let parent2 = node.parent;
|
31435
31440
|
while (isOuterExpression(parent2, kinds)) {
|
31436
31441
|
parent2 = parent2.parent;
|
@@ -40351,6 +40356,7 @@ var libEntries = [
|
|
40351
40356
|
["esnext.regexp", "lib.es2024.regexp.d.ts"],
|
40352
40357
|
["esnext.string", "lib.es2024.string.d.ts"],
|
40353
40358
|
["esnext.iterator", "lib.esnext.iterator.d.ts"],
|
40359
|
+
["esnext.promise", "lib.esnext.promise.d.ts"],
|
40354
40360
|
["decorators", "lib.decorators.d.ts"],
|
40355
40361
|
["decorators.legacy", "lib.decorators.legacy.d.ts"]
|
40356
40362
|
];
|
@@ -46411,6 +46417,7 @@ function createBinder() {
|
|
46411
46417
|
var preSwitchCaseFlow;
|
46412
46418
|
var activeLabelList;
|
46413
46419
|
var hasExplicitReturn;
|
46420
|
+
var inReturnPosition;
|
46414
46421
|
var hasFlowEffects;
|
46415
46422
|
var emitFlags;
|
46416
46423
|
var inStrictMode;
|
@@ -46483,6 +46490,7 @@ function createBinder() {
|
|
46483
46490
|
currentExceptionTarget = void 0;
|
46484
46491
|
activeLabelList = void 0;
|
46485
46492
|
hasExplicitReturn = false;
|
46493
|
+
inReturnPosition = false;
|
46486
46494
|
hasFlowEffects = false;
|
46487
46495
|
inAssignmentPattern = false;
|
46488
46496
|
emitFlags = 0 /* None */;
|
@@ -46719,6 +46727,8 @@ function createBinder() {
|
|
46719
46727
|
const saveContainer = container;
|
46720
46728
|
const saveThisParentContainer = thisParentContainer;
|
46721
46729
|
const savedBlockScopeContainer = blockScopeContainer;
|
46730
|
+
const savedInReturnPosition = inReturnPosition;
|
46731
|
+
if (node.kind === 219 /* ArrowFunction */ && node.body.kind !== 241 /* Block */) inReturnPosition = true;
|
46722
46732
|
if (containerFlags & 1 /* IsContainer */) {
|
46723
46733
|
if (node.kind !== 219 /* ArrowFunction */) {
|
46724
46734
|
thisParentContainer = container;
|
@@ -46796,6 +46806,7 @@ function createBinder() {
|
|
46796
46806
|
} else {
|
46797
46807
|
bindChildren(node);
|
46798
46808
|
}
|
46809
|
+
inReturnPosition = savedInReturnPosition;
|
46799
46810
|
container = saveContainer;
|
46800
46811
|
thisParentContainer = saveThisParentContainer;
|
46801
46812
|
blockScopeContainer = savedBlockScopeContainer;
|
@@ -47247,7 +47258,10 @@ function createBinder() {
|
|
47247
47258
|
currentFlow = finishFlowLabel(postIfLabel);
|
47248
47259
|
}
|
47249
47260
|
function bindReturnOrThrow(node) {
|
47261
|
+
const savedInReturnPosition = inReturnPosition;
|
47262
|
+
inReturnPosition = true;
|
47250
47263
|
bind(node.expression);
|
47264
|
+
inReturnPosition = savedInReturnPosition;
|
47251
47265
|
if (node.kind === 253 /* ReturnStatement */) {
|
47252
47266
|
hasExplicitReturn = true;
|
47253
47267
|
if (currentReturnTarget) {
|
@@ -47608,10 +47622,16 @@ function createBinder() {
|
|
47608
47622
|
hasFlowEffects = false;
|
47609
47623
|
bindCondition(node.condition, trueLabel, falseLabel);
|
47610
47624
|
currentFlow = finishFlowLabel(trueLabel);
|
47625
|
+
if (inReturnPosition) {
|
47626
|
+
node.flowNodeWhenTrue = currentFlow;
|
47627
|
+
}
|
47611
47628
|
bind(node.questionToken);
|
47612
47629
|
bind(node.whenTrue);
|
47613
47630
|
addAntecedent(postExpressionLabel, currentFlow);
|
47614
47631
|
currentFlow = finishFlowLabel(falseLabel);
|
47632
|
+
if (inReturnPosition) {
|
47633
|
+
node.flowNodeWhenFalse = currentFlow;
|
47634
|
+
}
|
47615
47635
|
bind(node.colonToken);
|
47616
47636
|
bind(node.whenFalse);
|
47617
47637
|
addAntecedent(postExpressionLabel, currentFlow);
|
@@ -50768,8 +50788,8 @@ function createTypeChecker(host) {
|
|
50768
50788
|
writeSignature: (signature, enclosingDeclaration, flags, kind, writer) => {
|
50769
50789
|
return signatureToString(signature, getParseTreeNode(enclosingDeclaration), flags, kind, writer);
|
50770
50790
|
},
|
50771
|
-
writeType: (type, enclosingDeclaration, flags, writer) => {
|
50772
|
-
return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer);
|
50791
|
+
writeType: (type, enclosingDeclaration, flags, writer, verbosityLevel, out) => {
|
50792
|
+
return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer, verbosityLevel, out);
|
50773
50793
|
},
|
50774
50794
|
writeSymbol: (symbol, enclosingDeclaration, meaning, flags, writer) => {
|
50775
50795
|
return symbolToString(symbol, getParseTreeNode(enclosingDeclaration), meaning, flags, writer);
|
@@ -51555,6 +51575,7 @@ function createTypeChecker(host) {
|
|
51555
51575
|
[".jsx", ".jsx"],
|
51556
51576
|
[".json", ".json"]
|
51557
51577
|
];
|
51578
|
+
var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
|
51558
51579
|
initializeTypeChecker();
|
51559
51580
|
return checker;
|
51560
51581
|
function isDefinitelyReferenceToGlobalSymbolObject(node) {
|
@@ -54690,14 +54711,18 @@ function createTypeChecker(host) {
|
|
54690
54711
|
return writer2;
|
54691
54712
|
}
|
54692
54713
|
}
|
54693
|
-
function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter("")) {
|
54694
|
-
const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation
|
54714
|
+
function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter(""), verbosityLevel, out) {
|
54715
|
+
const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */ || verbosityLevel !== void 0;
|
54695
54716
|
const typeNode = nodeBuilder.typeToTypeNode(
|
54696
54717
|
type,
|
54697
54718
|
enclosingDeclaration,
|
54698
|
-
toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0
|
54719
|
+
toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0),
|
54699
54720
|
/*internalFlags*/
|
54700
|
-
void 0
|
54721
|
+
void 0,
|
54722
|
+
/*tracker*/
|
54723
|
+
void 0,
|
54724
|
+
verbosityLevel,
|
54725
|
+
out
|
54701
54726
|
);
|
54702
54727
|
if (typeNode === void 0) return Debug.fail("should always get typenode");
|
54703
54728
|
const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
|
@@ -54929,31 +54954,127 @@ function createTypeChecker(host) {
|
|
54929
54954
|
};
|
54930
54955
|
return {
|
54931
54956
|
syntacticBuilderResolver,
|
54932
|
-
typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
|
54933
|
-
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
54934
|
-
|
54935
|
-
|
54936
|
-
|
54937
|
-
|
54938
|
-
|
54939
|
-
|
54940
|
-
|
54941
|
-
|
54942
|
-
)
|
54943
|
-
|
54944
|
-
|
54945
|
-
|
54946
|
-
|
54947
|
-
|
54948
|
-
|
54949
|
-
|
54950
|
-
)
|
54951
|
-
|
54952
|
-
|
54953
|
-
|
54954
|
-
|
54955
|
-
|
54956
|
-
|
54957
|
+
typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeToTypeNodeHelper(type, context), out),
|
54958
|
+
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
54959
|
+
enclosingDeclaration,
|
54960
|
+
flags,
|
54961
|
+
internalFlags,
|
54962
|
+
tracker,
|
54963
|
+
/*verbosityLevel*/
|
54964
|
+
void 0,
|
54965
|
+
(context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)
|
54966
|
+
),
|
54967
|
+
serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
54968
|
+
enclosingDeclaration,
|
54969
|
+
flags,
|
54970
|
+
internalFlags,
|
54971
|
+
tracker,
|
54972
|
+
/*verbosityLevel*/
|
54973
|
+
void 0,
|
54974
|
+
(context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)
|
54975
|
+
),
|
54976
|
+
serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
54977
|
+
enclosingDeclaration,
|
54978
|
+
flags,
|
54979
|
+
internalFlags,
|
54980
|
+
tracker,
|
54981
|
+
/*verbosityLevel*/
|
54982
|
+
void 0,
|
54983
|
+
(context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)
|
54984
|
+
),
|
54985
|
+
serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
54986
|
+
enclosingDeclaration,
|
54987
|
+
flags,
|
54988
|
+
internalFlags,
|
54989
|
+
tracker,
|
54990
|
+
/*verbosityLevel*/
|
54991
|
+
void 0,
|
54992
|
+
(context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)
|
54993
|
+
),
|
54994
|
+
indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
54995
|
+
enclosingDeclaration,
|
54996
|
+
flags,
|
54997
|
+
internalFlags,
|
54998
|
+
tracker,
|
54999
|
+
/*verbosityLevel*/
|
55000
|
+
void 0,
|
55001
|
+
(context) => indexInfoToIndexSignatureDeclarationHelper(
|
55002
|
+
indexInfo,
|
55003
|
+
context,
|
55004
|
+
/*typeNode*/
|
55005
|
+
void 0
|
55006
|
+
)
|
55007
|
+
),
|
55008
|
+
signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
55009
|
+
enclosingDeclaration,
|
55010
|
+
flags,
|
55011
|
+
internalFlags,
|
55012
|
+
tracker,
|
55013
|
+
/*verbosityLevel*/
|
55014
|
+
void 0,
|
55015
|
+
(context) => signatureToSignatureDeclarationHelper(signature, kind, context)
|
55016
|
+
),
|
55017
|
+
symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
55018
|
+
enclosingDeclaration,
|
55019
|
+
flags,
|
55020
|
+
internalFlags,
|
55021
|
+
tracker,
|
55022
|
+
/*verbosityLevel*/
|
55023
|
+
void 0,
|
55024
|
+
(context) => symbolToName(
|
55025
|
+
symbol,
|
55026
|
+
context,
|
55027
|
+
meaning,
|
55028
|
+
/*expectsIdentifier*/
|
55029
|
+
false
|
55030
|
+
)
|
55031
|
+
),
|
55032
|
+
symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
55033
|
+
enclosingDeclaration,
|
55034
|
+
flags,
|
55035
|
+
internalFlags,
|
55036
|
+
tracker,
|
55037
|
+
/*verbosityLevel*/
|
55038
|
+
void 0,
|
55039
|
+
(context) => symbolToExpression(symbol, context, meaning)
|
55040
|
+
),
|
55041
|
+
symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
55042
|
+
enclosingDeclaration,
|
55043
|
+
flags,
|
55044
|
+
internalFlags,
|
55045
|
+
tracker,
|
55046
|
+
/*verbosityLevel*/
|
55047
|
+
void 0,
|
55048
|
+
(context) => typeParametersToTypeParameterDeclarations(symbol, context)
|
55049
|
+
),
|
55050
|
+
symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
55051
|
+
enclosingDeclaration,
|
55052
|
+
flags,
|
55053
|
+
internalFlags,
|
55054
|
+
tracker,
|
55055
|
+
/*verbosityLevel*/
|
55056
|
+
void 0,
|
55057
|
+
(context) => symbolToParameterDeclaration(symbol, context)
|
55058
|
+
),
|
55059
|
+
typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeParameterToDeclaration(parameter, context)),
|
55060
|
+
symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
55061
|
+
enclosingDeclaration,
|
55062
|
+
flags,
|
55063
|
+
internalFlags,
|
55064
|
+
tracker,
|
55065
|
+
/*verbosityLevel*/
|
55066
|
+
void 0,
|
55067
|
+
(context) => symbolTableToDeclarationStatements(symbolTable, context)
|
55068
|
+
),
|
55069
|
+
symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
|
55070
|
+
enclosingDeclaration,
|
55071
|
+
flags,
|
55072
|
+
internalFlags,
|
55073
|
+
tracker,
|
55074
|
+
/*verbosityLevel*/
|
55075
|
+
void 0,
|
55076
|
+
(context) => symbolToNode(symbol, context, meaning)
|
55077
|
+
)
|
54957
55078
|
};
|
54958
55079
|
function getTypeFromTypeNode2(context, node, noMappedTypes) {
|
54959
55080
|
const type = getTypeFromTypeNodeWithoutContext(node);
|
@@ -54995,7 +55116,7 @@ function createTypeChecker(host) {
|
|
54995
55116
|
}
|
54996
55117
|
return symbolToExpression(symbol, context, meaning);
|
54997
55118
|
}
|
54998
|
-
function withContext2(enclosingDeclaration, flags, internalFlags, tracker, cb) {
|
55119
|
+
function withContext2(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, cb, out) {
|
54999
55120
|
const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : (internalFlags || 0 /* None */) & 4 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
|
55000
55121
|
const context = {
|
55001
55122
|
enclosingDeclaration,
|
@@ -55003,6 +55124,7 @@ function createTypeChecker(host) {
|
|
55003
55124
|
flags: flags || 0 /* None */,
|
55004
55125
|
internalFlags: internalFlags || 0 /* None */,
|
55005
55126
|
tracker: void 0,
|
55127
|
+
unfoldDepth: verbosityLevel ?? -1,
|
55006
55128
|
encounteredError: false,
|
55007
55129
|
suppressReportInferenceFallback: false,
|
55008
55130
|
reportedDiagnostic: false,
|
@@ -55024,13 +55146,18 @@ function createTypeChecker(host) {
|
|
55024
55146
|
typeParameterNamesByText: void 0,
|
55025
55147
|
typeParameterNamesByTextNextNameCount: void 0,
|
55026
55148
|
enclosingSymbolTypes: /* @__PURE__ */ new Map(),
|
55027
|
-
mapper: void 0
|
55149
|
+
mapper: void 0,
|
55150
|
+
depth: 0,
|
55151
|
+
couldUnfoldMore: false
|
55028
55152
|
};
|
55029
55153
|
context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
|
55030
55154
|
const resultingNode = cb(context);
|
55031
55155
|
if (context.truncating && context.flags & 1 /* NoTruncation */) {
|
55032
55156
|
context.tracker.reportTruncationError();
|
55033
55157
|
}
|
55158
|
+
if (out) {
|
55159
|
+
out.couldUnfoldMore = context.couldUnfoldMore;
|
55160
|
+
}
|
55034
55161
|
return context.encounteredError ? void 0 : resultingNode;
|
55035
55162
|
}
|
55036
55163
|
function addSymbolTypeToContext(context, symbol, type) {
|
@@ -55049,16 +55176,36 @@ function createTypeChecker(host) {
|
|
55049
55176
|
function saveRestoreFlags(context) {
|
55050
55177
|
const flags = context.flags;
|
55051
55178
|
const internalFlags = context.internalFlags;
|
55179
|
+
const depth = context.depth;
|
55052
55180
|
return restore;
|
55053
55181
|
function restore() {
|
55054
55182
|
context.flags = flags;
|
55055
55183
|
context.internalFlags = internalFlags;
|
55184
|
+
context.depth = depth;
|
55056
55185
|
}
|
55057
55186
|
}
|
55058
55187
|
function checkTruncationLength(context) {
|
55059
55188
|
if (context.truncating) return context.truncating;
|
55060
55189
|
return context.truncating = context.approximateLength > (context.flags & 1 /* NoTruncation */ ? noTruncationMaximumTruncationLength : defaultMaximumTruncationLength);
|
55061
55190
|
}
|
55191
|
+
function couldUnfoldType(type, context) {
|
55192
|
+
var _a;
|
55193
|
+
if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
|
55194
|
+
return false;
|
55195
|
+
}
|
55196
|
+
return context.depth < context.unfoldDepth || context.depth === context.unfoldDepth && !context.couldUnfoldMore;
|
55197
|
+
}
|
55198
|
+
function canUnfoldType(type, context) {
|
55199
|
+
var _a;
|
55200
|
+
if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
|
55201
|
+
return false;
|
55202
|
+
}
|
55203
|
+
const result = context.depth < context.unfoldDepth;
|
55204
|
+
if (!result) {
|
55205
|
+
context.couldUnfoldMore = true;
|
55206
|
+
}
|
55207
|
+
return result;
|
55208
|
+
}
|
55062
55209
|
function typeToTypeNodeHelper(type, context) {
|
55063
55210
|
const restoreFlags = saveRestoreFlags(context);
|
55064
55211
|
const typeNode = typeToTypeNodeWorker(type, context);
|
@@ -55206,16 +55353,27 @@ function createTypeChecker(host) {
|
|
55206
55353
|
return factory.createThisTypeNode();
|
55207
55354
|
}
|
55208
55355
|
if (!inTypeAlias && type.aliasSymbol && (context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */ || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) {
|
55209
|
-
|
55210
|
-
|
55211
|
-
|
55212
|
-
|
55356
|
+
if (!canUnfoldType(type, context)) {
|
55357
|
+
const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
|
55358
|
+
if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
|
55359
|
+
if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
|
55360
|
+
return factory.createArrayTypeNode(typeArgumentNodes[0]);
|
55361
|
+
}
|
55362
|
+
return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
|
55213
55363
|
}
|
55214
|
-
|
55364
|
+
context.depth += 1;
|
55215
55365
|
}
|
55216
55366
|
const objectFlags = getObjectFlags(type);
|
55217
55367
|
if (objectFlags & 4 /* Reference */) {
|
55218
55368
|
Debug.assert(!!(type.flags & 524288 /* Object */));
|
55369
|
+
if (canUnfoldType(type, context)) {
|
55370
|
+
context.depth += 1;
|
55371
|
+
return createAnonymousTypeNode(
|
55372
|
+
type,
|
55373
|
+
/*forceClassExpansion*/
|
55374
|
+
true
|
55375
|
+
);
|
55376
|
+
}
|
55219
55377
|
return type.node ? visitAndTransformType(type, typeReferenceToTypeNode) : typeReferenceToTypeNode(type);
|
55220
55378
|
}
|
55221
55379
|
if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
|
@@ -55245,6 +55403,14 @@ function createTypeChecker(host) {
|
|
55245
55403
|
void 0
|
55246
55404
|
);
|
55247
55405
|
}
|
55406
|
+
if (objectFlags & 3 /* ClassOrInterface */ && canUnfoldType(type, context)) {
|
55407
|
+
context.depth += 1;
|
55408
|
+
return createAnonymousTypeNode(
|
55409
|
+
type,
|
55410
|
+
/*forceClassExpansion*/
|
55411
|
+
true
|
55412
|
+
);
|
55413
|
+
}
|
55248
55414
|
if (type.symbol) {
|
55249
55415
|
return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
|
55250
55416
|
}
|
@@ -55448,7 +55614,7 @@ function createTypeChecker(host) {
|
|
55448
55614
|
}
|
55449
55615
|
return result;
|
55450
55616
|
}
|
55451
|
-
function createAnonymousTypeNode(type2) {
|
55617
|
+
function createAnonymousTypeNode(type2, forceClassExpansion = false) {
|
55452
55618
|
var _a2, _b2;
|
55453
55619
|
const typeId = type2.id;
|
55454
55620
|
const symbol = type2.symbol;
|
@@ -55471,7 +55637,7 @@ function createTypeChecker(host) {
|
|
55471
55637
|
const isInstanceType = isClassInstanceSide(type2) ? 788968 /* Type */ : 111551 /* Value */;
|
55472
55638
|
if (isJSConstructor(symbol.valueDeclaration)) {
|
55473
55639
|
return symbolToTypeNode(symbol, context, isInstanceType);
|
55474
|
-
} else if (symbol.flags & 32 /* Class */ && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
|
55640
|
+
} else if (symbol.flags & 32 /* Class */ && !forceClassExpansion && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
|
55475
55641
|
symbol,
|
55476
55642
|
context.enclosingDeclaration,
|
55477
55643
|
isInstanceType,
|
@@ -55515,7 +55681,7 @@ function createTypeChecker(host) {
|
|
55515
55681
|
if (id && !context.symbolDepth) {
|
55516
55682
|
context.symbolDepth = /* @__PURE__ */ new Map();
|
55517
55683
|
}
|
55518
|
-
const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
|
55684
|
+
const links = context.unfoldDepth >= 0 ? void 0 : context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
|
55519
55685
|
const key = `${getTypeId(type2)}|${context.flags}|${context.internalFlags}`;
|
55520
55686
|
if (links) {
|
55521
55687
|
links.serializedTypes || (links.serializedTypes = /* @__PURE__ */ new Map());
|
@@ -56430,7 +56596,7 @@ function createTypeChecker(host) {
|
|
56430
56596
|
return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
|
56431
56597
|
}
|
56432
56598
|
function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
|
56433
|
-
return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
|
56599
|
+
return !couldUnfoldType(type, context) && typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
|
56434
56600
|
}
|
56435
56601
|
function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
|
56436
56602
|
const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
|
@@ -57064,7 +57230,7 @@ function createTypeChecker(host) {
|
|
57064
57230
|
let result;
|
57065
57231
|
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
|
57066
57232
|
const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
|
57067
|
-
if (decl) {
|
57233
|
+
if (!couldUnfoldType(type, context) && decl) {
|
57068
57234
|
if (isAccessor(decl)) {
|
57069
57235
|
result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
|
57070
57236
|
} else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
|
@@ -63786,11 +63952,14 @@ function createTypeChecker(host) {
|
|
63786
63952
|
function isNoInferType(type) {
|
63787
63953
|
return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
|
63788
63954
|
}
|
63789
|
-
function
|
63790
|
-
return
|
63955
|
+
function isNarrowingSubstitutionType(type) {
|
63956
|
+
return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
|
63957
|
+
}
|
63958
|
+
function getSubstitutionType(baseType, constraint, isNarrowed) {
|
63959
|
+
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
|
63791
63960
|
}
|
63792
|
-
function getOrCreateSubstitutionType(baseType, constraint) {
|
63793
|
-
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
|
63961
|
+
function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
|
63962
|
+
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
|
63794
63963
|
const cached = substitutionTypes.get(id);
|
63795
63964
|
if (cached) {
|
63796
63965
|
return cached;
|
@@ -63798,6 +63967,9 @@ function createTypeChecker(host) {
|
|
63798
63967
|
const result = createType(33554432 /* Substitution */);
|
63799
63968
|
result.baseType = baseType;
|
63800
63969
|
result.constraint = constraint;
|
63970
|
+
if (isNarrowed) {
|
63971
|
+
result.objectFlags |= 16777216 /* IsNarrowingType */;
|
63972
|
+
}
|
63801
63973
|
substitutionTypes.set(id, result);
|
63802
63974
|
return result;
|
63803
63975
|
}
|
@@ -66000,7 +66172,7 @@ function createTypeChecker(host) {
|
|
66000
66172
|
function isDeferredType(type, checkTuples) {
|
66001
66173
|
return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
|
66002
66174
|
}
|
66003
|
-
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
|
66175
|
+
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
|
66004
66176
|
let result;
|
66005
66177
|
let extraTypes;
|
66006
66178
|
let tailCount = 0;
|
@@ -66017,10 +66189,11 @@ function createTypeChecker(host) {
|
|
66017
66189
|
if (checkType === wildcardType || extendsType === wildcardType) {
|
66018
66190
|
return wildcardType;
|
66019
66191
|
}
|
66192
|
+
const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
|
66020
66193
|
const checkTypeNode = skipTypeParentheses(root.node.checkType);
|
66021
66194
|
const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
|
66022
66195
|
const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
|
66023
|
-
const checkTypeDeferred = isDeferredType(
|
66196
|
+
const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
|
66024
66197
|
let combinedMapper;
|
66025
66198
|
if (root.inferTypeParameters) {
|
66026
66199
|
const context = createInferenceContext(
|
@@ -66039,8 +66212,8 @@ function createTypeChecker(host) {
|
|
66039
66212
|
}
|
66040
66213
|
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
|
66041
66214
|
if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
|
66042
|
-
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (
|
66043
|
-
if (
|
66215
|
+
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
|
66216
|
+
if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
|
66044
66217
|
(extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
|
66045
66218
|
}
|
66046
66219
|
const falseType2 = getTypeFromTypeNode(root.node.falseType);
|
@@ -66057,7 +66230,7 @@ function createTypeChecker(host) {
|
|
66057
66230
|
result = instantiateType(falseType2, mapper);
|
66058
66231
|
break;
|
66059
66232
|
}
|
66060
|
-
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(
|
66233
|
+
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
|
66061
66234
|
const trueType2 = getTypeFromTypeNode(root.node.trueType);
|
66062
66235
|
const trueMapper = combinedMapper || mapper;
|
66063
66236
|
if (canTailRecurse(trueType2, trueMapper)) {
|
@@ -67023,8 +67196,39 @@ function createTypeChecker(host) {
|
|
67023
67196
|
if (!result) {
|
67024
67197
|
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
|
67025
67198
|
const checkType = root.checkType;
|
67026
|
-
|
67027
|
-
|
67199
|
+
let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
|
67200
|
+
let narrowingBaseType;
|
67201
|
+
const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
|
67202
|
+
if (forNarrowing) {
|
67203
|
+
narrowingBaseType = distributionType.baseType;
|
67204
|
+
distributionType = getReducedType(distributionType.constraint);
|
67205
|
+
}
|
67206
|
+
if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
|
67207
|
+
if (narrowingBaseType) {
|
67208
|
+
result = mapTypeToIntersection(
|
67209
|
+
distributionType,
|
67210
|
+
(t) => getConditionalType(
|
67211
|
+
root,
|
67212
|
+
prependTypeMapping(checkType, getSubstitutionType(
|
67213
|
+
narrowingBaseType,
|
67214
|
+
t,
|
67215
|
+
/*isNarrowed*/
|
67216
|
+
true
|
67217
|
+
), newMapper),
|
67218
|
+
forConstraint,
|
67219
|
+
/*aliasSymbol*/
|
67220
|
+
void 0,
|
67221
|
+
/*aliasTypeArguments*/
|
67222
|
+
void 0,
|
67223
|
+
forNarrowing
|
67224
|
+
)
|
67225
|
+
);
|
67226
|
+
} else {
|
67227
|
+
result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
|
67228
|
+
}
|
67229
|
+
} else {
|
67230
|
+
result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
|
67231
|
+
}
|
67028
67232
|
root.instantiations.set(id, result);
|
67029
67233
|
}
|
67030
67234
|
return result;
|
@@ -68167,10 +68371,12 @@ function createTypeChecker(host) {
|
|
68167
68371
|
function shouldNormalizeIntersection(type) {
|
68168
68372
|
let hasInstantiable = false;
|
68169
68373
|
let hasNullableOrEmpty = false;
|
68374
|
+
let hasSubstitution = false;
|
68170
68375
|
for (const t of type.types) {
|
68171
68376
|
hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
|
68172
68377
|
hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
|
68173
|
-
|
68378
|
+
hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
|
68379
|
+
if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
|
68174
68380
|
}
|
68175
68381
|
return false;
|
68176
68382
|
}
|
@@ -73329,6 +73535,18 @@ function createTypeChecker(host) {
|
|
73329
73535
|
}
|
73330
73536
|
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
|
73331
73537
|
}
|
73538
|
+
function mapTypeToIntersection(type, mapper) {
|
73539
|
+
if (type.flags & 131072 /* Never */) {
|
73540
|
+
return type;
|
73541
|
+
}
|
73542
|
+
if (!(type.flags & 1048576 /* Union */)) {
|
73543
|
+
return mapper(type);
|
73544
|
+
}
|
73545
|
+
const origin = type.origin;
|
73546
|
+
const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
|
73547
|
+
const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
|
73548
|
+
return getIntersectionType(mappedTypes);
|
73549
|
+
}
|
73332
73550
|
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
|
73333
73551
|
return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
|
73334
73552
|
}
|
@@ -74911,11 +75129,11 @@ function createTypeChecker(host) {
|
|
74911
75129
|
));
|
74912
75130
|
return contextualType && !isGenericType(contextualType);
|
74913
75131
|
}
|
74914
|
-
function getNarrowableTypeForReference(type, reference, checkMode) {
|
75132
|
+
function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
|
74915
75133
|
if (isNoInferType(type)) {
|
74916
75134
|
type = type.baseType;
|
74917
75135
|
}
|
74918
|
-
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
75136
|
+
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
74919
75137
|
return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
|
74920
75138
|
}
|
74921
75139
|
function isExportOrExportExpression(location) {
|
@@ -76040,9 +76258,16 @@ function createTypeChecker(host) {
|
|
76040
76258
|
function getContextualTypeForReturnExpression(node, contextFlags) {
|
76041
76259
|
const func = getContainingFunction(node);
|
76042
76260
|
if (func) {
|
76261
|
+
const functionFlags = getFunctionFlags(func);
|
76262
|
+
const links = getNodeLinks(node);
|
76263
|
+
if (links.contextualReturnType) {
|
76264
|
+
if (functionFlags & 2 /* Async */) {
|
76265
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
76266
|
+
}
|
76267
|
+
return links.contextualReturnType;
|
76268
|
+
}
|
76043
76269
|
let contextualReturnType = getContextualReturnType(func, contextFlags);
|
76044
76270
|
if (contextualReturnType) {
|
76045
|
-
const functionFlags = getFunctionFlags(func);
|
76046
76271
|
if (functionFlags & 1 /* Generator */) {
|
76047
76272
|
const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
|
76048
76273
|
if (contextualReturnType.flags & 1048576 /* Union */) {
|
@@ -76740,6 +76965,13 @@ function createTypeChecker(host) {
|
|
76740
76965
|
if (index >= 0) {
|
76741
76966
|
return contextualTypes[index];
|
76742
76967
|
}
|
76968
|
+
const links = getNodeLinks(node);
|
76969
|
+
if (links.contextualReturnType) {
|
76970
|
+
if (node.flags & 65536 /* AwaitContext */) {
|
76971
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
76972
|
+
}
|
76973
|
+
return links.contextualReturnType;
|
76974
|
+
}
|
76743
76975
|
const { parent: parent2 } = node;
|
76744
76976
|
switch (parent2.kind) {
|
76745
76977
|
case 260 /* VariableDeclaration */:
|
@@ -79416,8 +79648,8 @@ function createTypeChecker(host) {
|
|
79416
79648
|
}
|
79417
79649
|
}
|
79418
79650
|
function getEffectiveCheckNode(argument) {
|
79419
|
-
|
79420
|
-
return
|
79651
|
+
const flags = isInJSFile(argument) ? 1 /* Parentheses */ | 32 /* Satisfies */ | -2147483648 /* ExcludeJSDocTypeAssertion */ : 1 /* Parentheses */ | 32 /* Satisfies */;
|
79652
|
+
return skipOuterExpressions(argument, flags);
|
79421
79653
|
}
|
79422
79654
|
function getSignatureApplicabilityError(node, args, signature, relation, checkMode, reportErrors2, containingMessageChain, inferenceContext) {
|
79423
79655
|
const errorOutputContainer = { errors: void 0, skipLogging: true };
|
@@ -79842,11 +80074,16 @@ function createTypeChecker(host) {
|
|
79842
80074
|
if (!result) {
|
79843
80075
|
result = chooseOverload(candidates, assignableRelation, isSingleNonGenericCandidate, signatureHelpTrailingComma);
|
79844
80076
|
}
|
80077
|
+
const links = getNodeLinks(node);
|
80078
|
+
if (links.resolvedSignature !== resolvingSignature && !candidatesOutArray) {
|
80079
|
+
Debug.assert(links.resolvedSignature);
|
80080
|
+
return links.resolvedSignature;
|
80081
|
+
}
|
79845
80082
|
if (result) {
|
79846
80083
|
return result;
|
79847
80084
|
}
|
79848
80085
|
result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
|
79849
|
-
|
80086
|
+
links.resolvedSignature = result;
|
79850
80087
|
if (reportErrors2) {
|
79851
80088
|
if (!headMessage && isInstanceof) {
|
79852
80089
|
headMessage = Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method;
|
@@ -80730,12 +80967,9 @@ function createTypeChecker(host) {
|
|
80730
80967
|
resolutionStart = resolutionTargets.length;
|
80731
80968
|
}
|
80732
80969
|
links.resolvedSignature = resolvingSignature;
|
80733
|
-
|
80970
|
+
const result = resolveSignature(node, candidatesOutArray, checkMode || 0 /* Normal */);
|
80734
80971
|
resolutionStart = saveResolutionStart;
|
80735
80972
|
if (result !== resolvingSignature) {
|
80736
|
-
if (links.resolvedSignature !== resolvingSignature) {
|
80737
|
-
result = links.resolvedSignature;
|
80738
|
-
}
|
80739
80973
|
links.resolvedSignature = flowLoopStart === flowLoopCount ? result : cached;
|
80740
80974
|
}
|
80741
80975
|
return result;
|
@@ -82411,19 +82645,7 @@ function createTypeChecker(host) {
|
|
82411
82645
|
const exprType = checkExpression(node.body);
|
82412
82646
|
const returnOrPromisedType = returnType && unwrapReturnType(returnType, functionFlags);
|
82413
82647
|
if (returnOrPromisedType) {
|
82414
|
-
|
82415
|
-
if ((functionFlags & 3 /* AsyncGenerator */) === 2 /* Async */) {
|
82416
|
-
const awaitedType = checkAwaitedType(
|
82417
|
-
exprType,
|
82418
|
-
/*withAlias*/
|
82419
|
-
false,
|
82420
|
-
effectiveCheckNode,
|
82421
|
-
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
82422
|
-
);
|
82423
|
-
checkTypeAssignableToAndOptionallyElaborate(awaitedType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
|
82424
|
-
} else {
|
82425
|
-
checkTypeAssignableToAndOptionallyElaborate(exprType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
|
82426
|
-
}
|
82648
|
+
checkReturnExpression(node, returnOrPromisedType, node.body, node.body, exprType);
|
82427
82649
|
}
|
82428
82650
|
}
|
82429
82651
|
}
|
@@ -82506,7 +82728,7 @@ function createTypeChecker(host) {
|
|
82506
82728
|
return false;
|
82507
82729
|
}
|
82508
82730
|
function checkReferenceExpression(expr, invalidReferenceMessage, invalidOptionalChainMessage) {
|
82509
|
-
const node = skipOuterExpressions(expr,
|
82731
|
+
const node = skipOuterExpressions(expr, 38 /* Assertions */ | 1 /* Parentheses */);
|
82510
82732
|
if (node.kind !== 80 /* Identifier */ && !isAccessExpression(node)) {
|
82511
82733
|
error2(expr, invalidReferenceMessage);
|
82512
82734
|
return false;
|
@@ -83157,7 +83379,7 @@ function createTypeChecker(host) {
|
|
83157
83379
|
if (isBinaryExpression(right) && (right.operatorToken.kind === 57 /* BarBarToken */ || right.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
|
83158
83380
|
grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
|
83159
83381
|
}
|
83160
|
-
const leftTarget = skipOuterExpressions(left,
|
83382
|
+
const leftTarget = skipOuterExpressions(left, 63 /* All */);
|
83161
83383
|
const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
|
83162
83384
|
if (nullishSemantics !== 3 /* Sometimes */) {
|
83163
83385
|
if (node.parent.kind === 226 /* BinaryExpression */) {
|
@@ -83178,6 +83400,7 @@ function createTypeChecker(host) {
|
|
83178
83400
|
case 223 /* AwaitExpression */:
|
83179
83401
|
case 213 /* CallExpression */:
|
83180
83402
|
case 212 /* ElementAccessExpression */:
|
83403
|
+
case 236 /* MetaProperty */:
|
83181
83404
|
case 214 /* NewExpression */:
|
83182
83405
|
case 211 /* PropertyAccessExpression */:
|
83183
83406
|
case 229 /* YieldExpression */:
|
@@ -87647,7 +87870,6 @@ function createTypeChecker(host) {
|
|
87647
87870
|
}
|
87648
87871
|
const signature = getSignatureFromDeclaration(container);
|
87649
87872
|
const returnType = getReturnTypeOfSignature(signature);
|
87650
|
-
const functionFlags = getFunctionFlags(container);
|
87651
87873
|
if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
|
87652
87874
|
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
87653
87875
|
if (container.kind === 178 /* SetAccessor */) {
|
@@ -87655,26 +87877,249 @@ function createTypeChecker(host) {
|
|
87655
87877
|
error2(node, Diagnostics.Setters_cannot_return_a_value);
|
87656
87878
|
}
|
87657
87879
|
} else if (container.kind === 176 /* Constructor */) {
|
87658
|
-
|
87880
|
+
const exprType2 = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
87881
|
+
if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType2, returnType, node, node.expression)) {
|
87659
87882
|
error2(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
|
87660
87883
|
}
|
87661
87884
|
} else if (getReturnTypeFromAnnotation(container)) {
|
87662
|
-
const unwrappedReturnType = unwrapReturnType(returnType,
|
87663
|
-
|
87664
|
-
exprType,
|
87665
|
-
/*withAlias*/
|
87666
|
-
false,
|
87667
|
-
node,
|
87668
|
-
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
87669
|
-
) : exprType;
|
87670
|
-
if (unwrappedReturnType) {
|
87671
|
-
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, node, node.expression);
|
87672
|
-
}
|
87885
|
+
const unwrappedReturnType = unwrapReturnType(returnType, getFunctionFlags(container)) ?? returnType;
|
87886
|
+
checkReturnExpression(container, unwrappedReturnType, node, node.expression, exprType);
|
87673
87887
|
}
|
87674
87888
|
} else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
|
87675
87889
|
error2(node, Diagnostics.Not_all_code_paths_return_a_value);
|
87676
87890
|
}
|
87677
87891
|
}
|
87892
|
+
function checkReturnExpression(container, unwrappedReturnType, node, expr, exprType, inConditionalExpression = false) {
|
87893
|
+
const excludeJSDocTypeAssertions = isInJSFile(node);
|
87894
|
+
const functionFlags = getFunctionFlags(container);
|
87895
|
+
if (expr) {
|
87896
|
+
const unwrappedExpr = skipParentheses(expr, excludeJSDocTypeAssertions);
|
87897
|
+
if (isConditionalExpression(unwrappedExpr)) {
|
87898
|
+
checkReturnExpression(
|
87899
|
+
container,
|
87900
|
+
unwrappedReturnType,
|
87901
|
+
node,
|
87902
|
+
unwrappedExpr.whenTrue,
|
87903
|
+
checkExpression(unwrappedExpr.whenTrue),
|
87904
|
+
/*inConditionalExpression*/
|
87905
|
+
true
|
87906
|
+
);
|
87907
|
+
checkReturnExpression(
|
87908
|
+
container,
|
87909
|
+
unwrappedReturnType,
|
87910
|
+
node,
|
87911
|
+
unwrappedExpr.whenFalse,
|
87912
|
+
checkExpression(unwrappedExpr.whenFalse),
|
87913
|
+
/*inConditionalExpression*/
|
87914
|
+
true
|
87915
|
+
);
|
87916
|
+
return;
|
87917
|
+
}
|
87918
|
+
}
|
87919
|
+
const inReturnStatement = node.kind === 253 /* ReturnStatement */;
|
87920
|
+
const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
87921
|
+
exprType,
|
87922
|
+
/*withAlias*/
|
87923
|
+
false,
|
87924
|
+
node,
|
87925
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
87926
|
+
) : exprType;
|
87927
|
+
const effectiveExpr = expr && getEffectiveCheckNode(expr);
|
87928
|
+
const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
|
87929
|
+
if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
|
87930
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
87931
|
+
return;
|
87932
|
+
}
|
87933
|
+
if (checkTypeAssignableTo(
|
87934
|
+
unwrappedExprType,
|
87935
|
+
unwrappedReturnType,
|
87936
|
+
/*errorNode*/
|
87937
|
+
void 0
|
87938
|
+
)) {
|
87939
|
+
return;
|
87940
|
+
}
|
87941
|
+
let narrowPosition = node;
|
87942
|
+
let narrowFlowNode = inReturnStatement && node.flowNode;
|
87943
|
+
if (expr && isConditionalExpression(expr.parent)) {
|
87944
|
+
narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
|
87945
|
+
narrowPosition = expr;
|
87946
|
+
}
|
87947
|
+
if (!narrowFlowNode) {
|
87948
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
87949
|
+
return;
|
87950
|
+
}
|
87951
|
+
const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
|
87952
|
+
container,
|
87953
|
+
/*includeThisTypes*/
|
87954
|
+
false
|
87955
|
+
), getEffectiveTypeParameterDeclarations(container));
|
87956
|
+
const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
|
87957
|
+
if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
|
87958
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
87959
|
+
return;
|
87960
|
+
}
|
87961
|
+
const narrowedTypeParameters = [];
|
87962
|
+
const narrowedTypes = [];
|
87963
|
+
for (const [typeParam, symbol, reference] of narrowableTypeParameters) {
|
87964
|
+
const narrowReference = factory.cloneNode(reference);
|
87965
|
+
narrowReference.id = void 0;
|
87966
|
+
getNodeLinks(narrowReference).resolvedSymbol = symbol;
|
87967
|
+
setParent(narrowReference, narrowPosition.parent);
|
87968
|
+
narrowReference.flowNode = narrowFlowNode;
|
87969
|
+
const initialType = getNarrowableTypeForReference(
|
87970
|
+
typeParam,
|
87971
|
+
narrowReference,
|
87972
|
+
/*checkMode*/
|
87973
|
+
void 0,
|
87974
|
+
/*forReturnTypeNarrowing*/
|
87975
|
+
true
|
87976
|
+
);
|
87977
|
+
if (initialType === typeParam) {
|
87978
|
+
continue;
|
87979
|
+
}
|
87980
|
+
const flowType = getFlowTypeOfReference(narrowReference, initialType);
|
87981
|
+
const exprType2 = getTypeFromFlowType(flowType);
|
87982
|
+
if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
|
87983
|
+
continue;
|
87984
|
+
}
|
87985
|
+
const narrowedType = getSubstitutionType(
|
87986
|
+
typeParam,
|
87987
|
+
exprType2,
|
87988
|
+
/*isNarrowed*/
|
87989
|
+
true
|
87990
|
+
);
|
87991
|
+
narrowedTypeParameters.push(typeParam);
|
87992
|
+
narrowedTypes.push(narrowedType);
|
87993
|
+
}
|
87994
|
+
const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
|
87995
|
+
const narrowedReturnType = instantiateType(
|
87996
|
+
unwrappedReturnType,
|
87997
|
+
narrowMapper
|
87998
|
+
);
|
87999
|
+
if (expr) {
|
88000
|
+
const links = getNodeLinks(expr);
|
88001
|
+
if (!links.contextualReturnType) {
|
88002
|
+
links.contextualReturnType = narrowedReturnType;
|
88003
|
+
}
|
88004
|
+
}
|
88005
|
+
const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
|
88006
|
+
const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
88007
|
+
narrowedExprType,
|
88008
|
+
/*withAlias*/
|
88009
|
+
false,
|
88010
|
+
node,
|
88011
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
88012
|
+
) : narrowedExprType;
|
88013
|
+
checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
|
88014
|
+
}
|
88015
|
+
function getNarrowableTypeParameters(candidates) {
|
88016
|
+
const narrowableParams = [];
|
88017
|
+
for (const typeParam of candidates) {
|
88018
|
+
const constraint = getConstraintOfTypeParameter(typeParam);
|
88019
|
+
if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
|
88020
|
+
if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
|
88021
|
+
const declaration = typeParam.symbol.declarations[0];
|
88022
|
+
const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
|
88023
|
+
if (!isFunctionLike(container)) continue;
|
88024
|
+
let reference;
|
88025
|
+
let hasInvalidReference = false;
|
88026
|
+
for (const paramDecl of container.parameters) {
|
88027
|
+
const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
|
88028
|
+
if (!typeNode) continue;
|
88029
|
+
if (isTypeParameterReferenced(typeParam, typeNode)) {
|
88030
|
+
let candidateReference;
|
88031
|
+
if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
|
88032
|
+
if (reference) {
|
88033
|
+
hasInvalidReference = true;
|
88034
|
+
break;
|
88035
|
+
}
|
88036
|
+
reference = candidateReference;
|
88037
|
+
} else {
|
88038
|
+
hasInvalidReference = true;
|
88039
|
+
break;
|
88040
|
+
}
|
88041
|
+
}
|
88042
|
+
}
|
88043
|
+
if (!hasInvalidReference && reference) {
|
88044
|
+
const symbol = getResolvedSymbol(reference);
|
88045
|
+
if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
|
88046
|
+
}
|
88047
|
+
}
|
88048
|
+
}
|
88049
|
+
return narrowableParams;
|
88050
|
+
function getValidParameterReference(paramDecl, constraint) {
|
88051
|
+
if (!isIdentifier(paramDecl.name)) return;
|
88052
|
+
const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
|
88053
|
+
if (isOptional && !containsUndefinedType(constraint)) return;
|
88054
|
+
return paramDecl.name;
|
88055
|
+
}
|
88056
|
+
function isReferenceToTypeParameter(typeParam, node) {
|
88057
|
+
return getTypeFromTypeReference(node) === typeParam;
|
88058
|
+
}
|
88059
|
+
function isTypeParameterReferenced(typeParam, node) {
|
88060
|
+
return isReferenced(node);
|
88061
|
+
function isReferenced(node2) {
|
88062
|
+
if (isTypeReferenceNode(node2)) {
|
88063
|
+
return isReferenceToTypeParameter(typeParam, node2);
|
88064
|
+
}
|
88065
|
+
if (isTypeQueryNode(node2)) {
|
88066
|
+
return isTypeParameterPossiblyReferenced(typeParam, node2);
|
88067
|
+
}
|
88068
|
+
return !!forEachChild(node2, isReferenced);
|
88069
|
+
}
|
88070
|
+
}
|
88071
|
+
}
|
88072
|
+
function isNarrowableReturnType(returnType) {
|
88073
|
+
return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
|
88074
|
+
}
|
88075
|
+
function isNarrowableConditionalType(type, mapper) {
|
88076
|
+
const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
|
88077
|
+
const mapped = getMappedType(t, mapper);
|
88078
|
+
if (isNarrowingSubstitutionType(mapped)) {
|
88079
|
+
return mapped.baseType;
|
88080
|
+
}
|
88081
|
+
return mapped;
|
88082
|
+
});
|
88083
|
+
const id = `${type.id}:${getTypeListId(typeArguments)}`;
|
88084
|
+
let result = narrowableReturnTypeCache.get(id);
|
88085
|
+
if (result === void 0) {
|
88086
|
+
const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
|
88087
|
+
const instantiatedType = instantiateType(type, nonNarrowingMapper);
|
88088
|
+
result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
|
88089
|
+
narrowableReturnTypeCache.set(id, result);
|
88090
|
+
}
|
88091
|
+
return result;
|
88092
|
+
}
|
88093
|
+
function isNarrowableConditionalTypeWorker(type) {
|
88094
|
+
if (!type.root.isDistributive) {
|
88095
|
+
return false;
|
88096
|
+
}
|
88097
|
+
if (type.root.inferTypeParameters) {
|
88098
|
+
return false;
|
88099
|
+
}
|
88100
|
+
if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
|
88101
|
+
return false;
|
88102
|
+
}
|
88103
|
+
const constraintType = getConstraintOfTypeParameter(type.checkType);
|
88104
|
+
if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
|
88105
|
+
return false;
|
88106
|
+
}
|
88107
|
+
if (!everyType(type.extendsType, (extendsType) => some(
|
88108
|
+
constraintType.types,
|
88109
|
+
(constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
|
88110
|
+
))) {
|
88111
|
+
return false;
|
88112
|
+
}
|
88113
|
+
const trueType2 = getTrueTypeFromConditionalType(type);
|
88114
|
+
const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
|
88115
|
+
if (!isValidTrueType) return false;
|
88116
|
+
const falseType2 = getFalseTypeFromConditionalType(type);
|
88117
|
+
const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
|
88118
|
+
return isValidFalseType;
|
88119
|
+
}
|
88120
|
+
function isConditionalType(type) {
|
88121
|
+
return !!(type.flags & 16777216 /* Conditional */);
|
88122
|
+
}
|
87678
88123
|
function checkWithStatement(node) {
|
87679
88124
|
if (!checkGrammarStatementInAmbientContext(node)) {
|
87680
88125
|
if (node.flags & 65536 /* AwaitContext */) {
|
@@ -97830,7 +98275,7 @@ function transformTypeScript(context) {
|
|
97830
98275
|
return updated;
|
97831
98276
|
}
|
97832
98277
|
function visitParenthesizedExpression(node) {
|
97833
|
-
const innerExpression = skipOuterExpressions(node.expression, ~(
|
98278
|
+
const innerExpression = skipOuterExpressions(node.expression, ~(38 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
|
97834
98279
|
if (isAssertionExpression(innerExpression) || isSatisfiesExpression(innerExpression)) {
|
97835
98280
|
const expression = visitNode(node.expression, visitor, isExpression);
|
97836
98281
|
Debug.assert(expression);
|
@@ -139818,9 +140263,9 @@ function mapToDisplayParts(writeDisplayParts) {
|
|
139818
140263
|
displayPartWriter.clear();
|
139819
140264
|
}
|
139820
140265
|
}
|
139821
|
-
function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags = 0 /* None
|
140266
|
+
function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags = 0 /* None */, verbosityLevel, out) {
|
139822
140267
|
return mapToDisplayParts((writer) => {
|
139823
|
-
typechecker.writeType(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer);
|
140268
|
+
typechecker.writeType(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer, verbosityLevel, out);
|
139824
140269
|
});
|
139825
140270
|
}
|
139826
140271
|
function symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration, meaning, flags = 0 /* None */) {
|
@@ -151797,7 +152242,7 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
|
|
151797
152242
|
synchronizeHostData();
|
151798
152243
|
return ts_Completions_exports.getCompletionEntrySymbol(program, log, getValidSourceFile(fileName), position, { name, source }, host, preferences);
|
151799
152244
|
}
|
151800
|
-
function getQuickInfoAtPosition(fileName, position) {
|
152245
|
+
function getQuickInfoAtPosition(fileName, position, verbosityLevel) {
|
151801
152246
|
synchronizeHostData();
|
151802
152247
|
const sourceFile = getValidSourceFile(fileName);
|
151803
152248
|
const node = getTouchingPropertyName(sourceFile, position);
|
@@ -151813,19 +152258,41 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
|
|
151813
152258
|
kind: "" /* unknown */,
|
151814
152259
|
kindModifiers: "" /* none */,
|
151815
152260
|
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
|
151816
|
-
displayParts: typeChecker.runWithCancellationToken(cancellationToken, (typeChecker2) => typeToDisplayParts(
|
152261
|
+
displayParts: typeChecker.runWithCancellationToken(cancellationToken, (typeChecker2) => typeToDisplayParts(
|
152262
|
+
typeChecker2,
|
152263
|
+
type,
|
152264
|
+
getContainerNode(nodeForQuickInfo),
|
152265
|
+
/*flags*/
|
152266
|
+
void 0,
|
152267
|
+
verbosityLevel
|
152268
|
+
)),
|
151817
152269
|
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : void 0,
|
151818
152270
|
tags: type.symbol ? type.symbol.getJsDocTags(typeChecker) : void 0
|
151819
152271
|
};
|
151820
152272
|
}
|
151821
|
-
const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(
|
152273
|
+
const { symbolKind, displayParts, documentation, tags, canIncreaseVerbosityLevel } = typeChecker.runWithCancellationToken(
|
152274
|
+
cancellationToken,
|
152275
|
+
(typeChecker2) => ts_SymbolDisplay_exports.getSymbolDisplayPartsDocumentationAndSymbolKind(
|
152276
|
+
typeChecker2,
|
152277
|
+
symbol,
|
152278
|
+
sourceFile,
|
152279
|
+
getContainerNode(nodeForQuickInfo),
|
152280
|
+
nodeForQuickInfo,
|
152281
|
+
/*semanticMeaning*/
|
152282
|
+
void 0,
|
152283
|
+
/*alias*/
|
152284
|
+
void 0,
|
152285
|
+
verbosityLevel
|
152286
|
+
)
|
152287
|
+
);
|
151822
152288
|
return {
|
151823
152289
|
kind: symbolKind,
|
151824
152290
|
kindModifiers: ts_SymbolDisplay_exports.getSymbolModifiers(typeChecker, symbol),
|
151825
152291
|
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
|
151826
152292
|
displayParts,
|
151827
152293
|
documentation,
|
151828
|
-
tags
|
152294
|
+
tags,
|
152295
|
+
canIncreaseVerbosityLevel
|
151829
152296
|
};
|
151830
152297
|
}
|
151831
152298
|
function preparePasteEditsForFile(fileName, copiedTextRange) {
|
@@ -176901,7 +177368,7 @@ function getSymbolModifiers(typeChecker, symbol) {
|
|
176901
177368
|
}
|
176902
177369
|
return modifiers.size > 0 ? arrayFrom(modifiers.values()).join(",") : "" /* none */;
|
176903
177370
|
}
|
176904
|
-
function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symbol, sourceFile, enclosingDeclaration, location, type, semanticMeaning, alias) {
|
177371
|
+
function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symbol, sourceFile, enclosingDeclaration, location, type, semanticMeaning, alias, verbosityLevel) {
|
176905
177372
|
var _a;
|
176906
177373
|
const displayParts = [];
|
176907
177374
|
let documentation = [];
|
@@ -176913,6 +177380,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
176913
177380
|
let documentationFromAlias;
|
176914
177381
|
let tagsFromAlias;
|
176915
177382
|
let hasMultipleSignatures = false;
|
177383
|
+
const typeWriterOut = verbosityLevel !== void 0 ? { couldUnfoldMore: false } : void 0;
|
176916
177384
|
if (location.kind === 110 /* ThisKeyword */ && !isThisExpression) {
|
176917
177385
|
return { displayParts: [keywordPart(110 /* ThisKeyword */)], documentation: [], symbolKind: "primitive type" /* primitiveType */, tags: void 0 };
|
176918
177386
|
}
|
@@ -177072,7 +177540,17 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177072
177540
|
displayParts.push(spacePart());
|
177073
177541
|
displayParts.push(operatorPart(64 /* EqualsToken */));
|
177074
177542
|
displayParts.push(spacePart());
|
177075
|
-
addRange(
|
177543
|
+
addRange(
|
177544
|
+
displayParts,
|
177545
|
+
typeToDisplayParts(
|
177546
|
+
typeChecker,
|
177547
|
+
location.parent && isConstTypeReference(location.parent) ? typeChecker.getTypeAtLocation(location.parent) : typeChecker.getDeclaredTypeOfSymbol(symbol),
|
177548
|
+
enclosingDeclaration,
|
177549
|
+
8388608 /* InTypeAlias */,
|
177550
|
+
verbosityLevel,
|
177551
|
+
typeWriterOut
|
177552
|
+
)
|
177553
|
+
);
|
177076
177554
|
}
|
177077
177555
|
if (symbolFlags & 384 /* Enum */) {
|
177078
177556
|
prefixNextMeaning();
|
@@ -177231,12 +177709,32 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177231
177709
|
displayParts.push(spacePart());
|
177232
177710
|
if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */ && symbolKind !== "index" /* indexSignatureElement */) {
|
177233
177711
|
const typeParameterParts = mapToDisplayParts((writer) => {
|
177234
|
-
const param = typeChecker.typeParameterToDeclaration(
|
177712
|
+
const param = typeChecker.typeParameterToDeclaration(
|
177713
|
+
type,
|
177714
|
+
enclosingDeclaration,
|
177715
|
+
symbolDisplayNodeBuilderFlags,
|
177716
|
+
/*internalFlags*/
|
177717
|
+
void 0,
|
177718
|
+
/*tracker*/
|
177719
|
+
void 0,
|
177720
|
+
verbosityLevel
|
177721
|
+
);
|
177235
177722
|
getPrinter().writeNode(4 /* Unspecified */, param, getSourceFileOfNode(getParseTreeNode(enclosingDeclaration)), writer);
|
177236
177723
|
});
|
177237
177724
|
addRange(displayParts, typeParameterParts);
|
177238
177725
|
} else {
|
177239
|
-
addRange(
|
177726
|
+
addRange(
|
177727
|
+
displayParts,
|
177728
|
+
typeToDisplayParts(
|
177729
|
+
typeChecker,
|
177730
|
+
type,
|
177731
|
+
enclosingDeclaration,
|
177732
|
+
/*flags*/
|
177733
|
+
void 0,
|
177734
|
+
verbosityLevel,
|
177735
|
+
typeWriterOut
|
177736
|
+
)
|
177737
|
+
);
|
177240
177738
|
}
|
177241
177739
|
if (isTransientSymbol(symbol) && symbol.links.target && isTransientSymbol(symbol.links.target) && symbol.links.target.links.tupleLabelDeclaration) {
|
177242
177740
|
const labelDecl = symbol.links.target.links.tupleLabelDeclaration;
|
@@ -177301,7 +177799,13 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177301
177799
|
if (tags.length === 0 && tagsFromAlias) {
|
177302
177800
|
tags = tagsFromAlias;
|
177303
177801
|
}
|
177304
|
-
return {
|
177802
|
+
return {
|
177803
|
+
displayParts,
|
177804
|
+
documentation,
|
177805
|
+
symbolKind,
|
177806
|
+
tags: tags.length === 0 ? void 0 : tags,
|
177807
|
+
canIncreaseVerbosityLevel: typeWriterOut == null ? void 0 : typeWriterOut.couldUnfoldMore
|
177808
|
+
};
|
177305
177809
|
function getPrinter() {
|
177306
177810
|
return createPrinterWithRemoveComments();
|
177307
177811
|
}
|
@@ -177414,7 +177918,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177414
177918
|
addRange(displayParts, typeParameterParts);
|
177415
177919
|
}
|
177416
177920
|
}
|
177417
|
-
function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias) {
|
177921
|
+
function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias, verbosityLevel) {
|
177418
177922
|
return getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
|
177419
177923
|
typeChecker,
|
177420
177924
|
symbol,
|
@@ -177424,7 +177928,8 @@ function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, so
|
|
177424
177928
|
/*type*/
|
177425
177929
|
void 0,
|
177426
177930
|
semanticMeaning,
|
177427
|
-
alias
|
177931
|
+
alias,
|
177932
|
+
verbosityLevel
|
177428
177933
|
);
|
177429
177934
|
}
|
177430
177935
|
function isLocalVariableOrFunction(symbol) {
|
@@ -194367,7 +194872,7 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
|
|
194367
194872
|
getQuickInfoWorker(args, simplifiedResult) {
|
194368
194873
|
const { file, project } = this.getFileAndProject(args);
|
194369
194874
|
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file);
|
194370
|
-
const quickInfo = project.getLanguageService().getQuickInfoAtPosition(file, this.getPosition(args, scriptInfo));
|
194875
|
+
const quickInfo = project.getLanguageService().getQuickInfoAtPosition(file, this.getPosition(args, scriptInfo), args.verbosityLevel);
|
194371
194876
|
if (!quickInfo) {
|
194372
194877
|
return void 0;
|
194373
194878
|
}
|
@@ -194381,7 +194886,8 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
|
|
194381
194886
|
end: scriptInfo.positionToLineOffset(textSpanEnd(quickInfo.textSpan)),
|
194382
194887
|
displayString,
|
194383
194888
|
documentation: useDisplayParts ? this.mapDisplayParts(quickInfo.documentation, project) : displayPartsToString(quickInfo.documentation),
|
194384
|
-
tags: this.mapJSDocTagInfo(quickInfo.tags, project, useDisplayParts)
|
194889
|
+
tags: this.mapJSDocTagInfo(quickInfo.tags, project, useDisplayParts),
|
194890
|
+
canIncreaseVerbosityLevel: quickInfo.canIncreaseVerbosityLevel
|
194385
194891
|
};
|
194386
194892
|
} else {
|
194387
194893
|
return useDisplayParts ? quickInfo : {
|