typescript 5.7.0-dev.20241104 → 5.8.0-dev.20241106
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 +548 -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 +627 -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.20241106`;
|
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 */) {
|
@@ -83193,6 +83415,8 @@ function createTypeChecker(host) {
|
|
83193
83415
|
case 56 /* AmpersandAmpersandToken */:
|
83194
83416
|
case 77 /* AmpersandAmpersandEqualsToken */:
|
83195
83417
|
return 3 /* Sometimes */;
|
83418
|
+
case 28 /* CommaToken */:
|
83419
|
+
return getSyntacticNullishnessSemantics(node.right);
|
83196
83420
|
}
|
83197
83421
|
return 2 /* Never */;
|
83198
83422
|
case 227 /* ConditionalExpression */:
|
@@ -87645,7 +87869,6 @@ function createTypeChecker(host) {
|
|
87645
87869
|
}
|
87646
87870
|
const signature = getSignatureFromDeclaration(container);
|
87647
87871
|
const returnType = getReturnTypeOfSignature(signature);
|
87648
|
-
const functionFlags = getFunctionFlags(container);
|
87649
87872
|
if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
|
87650
87873
|
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
87651
87874
|
if (container.kind === 178 /* SetAccessor */) {
|
@@ -87653,26 +87876,249 @@ function createTypeChecker(host) {
|
|
87653
87876
|
error2(node, Diagnostics.Setters_cannot_return_a_value);
|
87654
87877
|
}
|
87655
87878
|
} else if (container.kind === 176 /* Constructor */) {
|
87656
|
-
|
87879
|
+
const exprType2 = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
87880
|
+
if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType2, returnType, node, node.expression)) {
|
87657
87881
|
error2(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
|
87658
87882
|
}
|
87659
87883
|
} else if (getReturnTypeFromAnnotation(container)) {
|
87660
|
-
const unwrappedReturnType = unwrapReturnType(returnType,
|
87661
|
-
|
87662
|
-
exprType,
|
87663
|
-
/*withAlias*/
|
87664
|
-
false,
|
87665
|
-
node,
|
87666
|
-
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
87667
|
-
) : exprType;
|
87668
|
-
if (unwrappedReturnType) {
|
87669
|
-
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, node, node.expression);
|
87670
|
-
}
|
87884
|
+
const unwrappedReturnType = unwrapReturnType(returnType, getFunctionFlags(container)) ?? returnType;
|
87885
|
+
checkReturnExpression(container, unwrappedReturnType, node, node.expression, exprType);
|
87671
87886
|
}
|
87672
87887
|
} else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
|
87673
87888
|
error2(node, Diagnostics.Not_all_code_paths_return_a_value);
|
87674
87889
|
}
|
87675
87890
|
}
|
87891
|
+
function checkReturnExpression(container, unwrappedReturnType, node, expr, exprType, inConditionalExpression = false) {
|
87892
|
+
const excludeJSDocTypeAssertions = isInJSFile(node);
|
87893
|
+
const functionFlags = getFunctionFlags(container);
|
87894
|
+
if (expr) {
|
87895
|
+
const unwrappedExpr = skipParentheses(expr, excludeJSDocTypeAssertions);
|
87896
|
+
if (isConditionalExpression(unwrappedExpr)) {
|
87897
|
+
checkReturnExpression(
|
87898
|
+
container,
|
87899
|
+
unwrappedReturnType,
|
87900
|
+
node,
|
87901
|
+
unwrappedExpr.whenTrue,
|
87902
|
+
checkExpression(unwrappedExpr.whenTrue),
|
87903
|
+
/*inConditionalExpression*/
|
87904
|
+
true
|
87905
|
+
);
|
87906
|
+
checkReturnExpression(
|
87907
|
+
container,
|
87908
|
+
unwrappedReturnType,
|
87909
|
+
node,
|
87910
|
+
unwrappedExpr.whenFalse,
|
87911
|
+
checkExpression(unwrappedExpr.whenFalse),
|
87912
|
+
/*inConditionalExpression*/
|
87913
|
+
true
|
87914
|
+
);
|
87915
|
+
return;
|
87916
|
+
}
|
87917
|
+
}
|
87918
|
+
const inReturnStatement = node.kind === 253 /* ReturnStatement */;
|
87919
|
+
const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
87920
|
+
exprType,
|
87921
|
+
/*withAlias*/
|
87922
|
+
false,
|
87923
|
+
node,
|
87924
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
87925
|
+
) : exprType;
|
87926
|
+
const effectiveExpr = expr && getEffectiveCheckNode(expr);
|
87927
|
+
const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
|
87928
|
+
if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
|
87929
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
87930
|
+
return;
|
87931
|
+
}
|
87932
|
+
if (checkTypeAssignableTo(
|
87933
|
+
unwrappedExprType,
|
87934
|
+
unwrappedReturnType,
|
87935
|
+
/*errorNode*/
|
87936
|
+
void 0
|
87937
|
+
)) {
|
87938
|
+
return;
|
87939
|
+
}
|
87940
|
+
let narrowPosition = node;
|
87941
|
+
let narrowFlowNode = inReturnStatement && node.flowNode;
|
87942
|
+
if (expr && isConditionalExpression(expr.parent)) {
|
87943
|
+
narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
|
87944
|
+
narrowPosition = expr;
|
87945
|
+
}
|
87946
|
+
if (!narrowFlowNode) {
|
87947
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
87948
|
+
return;
|
87949
|
+
}
|
87950
|
+
const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
|
87951
|
+
container,
|
87952
|
+
/*includeThisTypes*/
|
87953
|
+
false
|
87954
|
+
), getEffectiveTypeParameterDeclarations(container));
|
87955
|
+
const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
|
87956
|
+
if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
|
87957
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
87958
|
+
return;
|
87959
|
+
}
|
87960
|
+
const narrowedTypeParameters = [];
|
87961
|
+
const narrowedTypes = [];
|
87962
|
+
for (const [typeParam, symbol, reference] of narrowableTypeParameters) {
|
87963
|
+
const narrowReference = factory.cloneNode(reference);
|
87964
|
+
narrowReference.id = void 0;
|
87965
|
+
getNodeLinks(narrowReference).resolvedSymbol = symbol;
|
87966
|
+
setParent(narrowReference, narrowPosition.parent);
|
87967
|
+
narrowReference.flowNode = narrowFlowNode;
|
87968
|
+
const initialType = getNarrowableTypeForReference(
|
87969
|
+
typeParam,
|
87970
|
+
narrowReference,
|
87971
|
+
/*checkMode*/
|
87972
|
+
void 0,
|
87973
|
+
/*forReturnTypeNarrowing*/
|
87974
|
+
true
|
87975
|
+
);
|
87976
|
+
if (initialType === typeParam) {
|
87977
|
+
continue;
|
87978
|
+
}
|
87979
|
+
const flowType = getFlowTypeOfReference(narrowReference, initialType);
|
87980
|
+
const exprType2 = getTypeFromFlowType(flowType);
|
87981
|
+
if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
|
87982
|
+
continue;
|
87983
|
+
}
|
87984
|
+
const narrowedType = getSubstitutionType(
|
87985
|
+
typeParam,
|
87986
|
+
exprType2,
|
87987
|
+
/*isNarrowed*/
|
87988
|
+
true
|
87989
|
+
);
|
87990
|
+
narrowedTypeParameters.push(typeParam);
|
87991
|
+
narrowedTypes.push(narrowedType);
|
87992
|
+
}
|
87993
|
+
const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
|
87994
|
+
const narrowedReturnType = instantiateType(
|
87995
|
+
unwrappedReturnType,
|
87996
|
+
narrowMapper
|
87997
|
+
);
|
87998
|
+
if (expr) {
|
87999
|
+
const links = getNodeLinks(expr);
|
88000
|
+
if (!links.contextualReturnType) {
|
88001
|
+
links.contextualReturnType = narrowedReturnType;
|
88002
|
+
}
|
88003
|
+
}
|
88004
|
+
const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
|
88005
|
+
const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
88006
|
+
narrowedExprType,
|
88007
|
+
/*withAlias*/
|
88008
|
+
false,
|
88009
|
+
node,
|
88010
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
88011
|
+
) : narrowedExprType;
|
88012
|
+
checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
|
88013
|
+
}
|
88014
|
+
function getNarrowableTypeParameters(candidates) {
|
88015
|
+
const narrowableParams = [];
|
88016
|
+
for (const typeParam of candidates) {
|
88017
|
+
const constraint = getConstraintOfTypeParameter(typeParam);
|
88018
|
+
if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
|
88019
|
+
if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
|
88020
|
+
const declaration = typeParam.symbol.declarations[0];
|
88021
|
+
const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
|
88022
|
+
if (!isFunctionLike(container)) continue;
|
88023
|
+
let reference;
|
88024
|
+
let hasInvalidReference = false;
|
88025
|
+
for (const paramDecl of container.parameters) {
|
88026
|
+
const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
|
88027
|
+
if (!typeNode) continue;
|
88028
|
+
if (isTypeParameterReferenced(typeParam, typeNode)) {
|
88029
|
+
let candidateReference;
|
88030
|
+
if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
|
88031
|
+
if (reference) {
|
88032
|
+
hasInvalidReference = true;
|
88033
|
+
break;
|
88034
|
+
}
|
88035
|
+
reference = candidateReference;
|
88036
|
+
} else {
|
88037
|
+
hasInvalidReference = true;
|
88038
|
+
break;
|
88039
|
+
}
|
88040
|
+
}
|
88041
|
+
}
|
88042
|
+
if (!hasInvalidReference && reference) {
|
88043
|
+
const symbol = getResolvedSymbol(reference);
|
88044
|
+
if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
|
88045
|
+
}
|
88046
|
+
}
|
88047
|
+
}
|
88048
|
+
return narrowableParams;
|
88049
|
+
function getValidParameterReference(paramDecl, constraint) {
|
88050
|
+
if (!isIdentifier(paramDecl.name)) return;
|
88051
|
+
const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
|
88052
|
+
if (isOptional && !containsUndefinedType(constraint)) return;
|
88053
|
+
return paramDecl.name;
|
88054
|
+
}
|
88055
|
+
function isReferenceToTypeParameter(typeParam, node) {
|
88056
|
+
return getTypeFromTypeReference(node) === typeParam;
|
88057
|
+
}
|
88058
|
+
function isTypeParameterReferenced(typeParam, node) {
|
88059
|
+
return isReferenced(node);
|
88060
|
+
function isReferenced(node2) {
|
88061
|
+
if (isTypeReferenceNode(node2)) {
|
88062
|
+
return isReferenceToTypeParameter(typeParam, node2);
|
88063
|
+
}
|
88064
|
+
if (isTypeQueryNode(node2)) {
|
88065
|
+
return isTypeParameterPossiblyReferenced(typeParam, node2);
|
88066
|
+
}
|
88067
|
+
return !!forEachChild(node2, isReferenced);
|
88068
|
+
}
|
88069
|
+
}
|
88070
|
+
}
|
88071
|
+
function isNarrowableReturnType(returnType) {
|
88072
|
+
return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
|
88073
|
+
}
|
88074
|
+
function isNarrowableConditionalType(type, mapper) {
|
88075
|
+
const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
|
88076
|
+
const mapped = getMappedType(t, mapper);
|
88077
|
+
if (isNarrowingSubstitutionType(mapped)) {
|
88078
|
+
return mapped.baseType;
|
88079
|
+
}
|
88080
|
+
return mapped;
|
88081
|
+
});
|
88082
|
+
const id = `${type.id}:${getTypeListId(typeArguments)}`;
|
88083
|
+
let result = narrowableReturnTypeCache.get(id);
|
88084
|
+
if (result === void 0) {
|
88085
|
+
const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
|
88086
|
+
const instantiatedType = instantiateType(type, nonNarrowingMapper);
|
88087
|
+
result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
|
88088
|
+
narrowableReturnTypeCache.set(id, result);
|
88089
|
+
}
|
88090
|
+
return result;
|
88091
|
+
}
|
88092
|
+
function isNarrowableConditionalTypeWorker(type) {
|
88093
|
+
if (!type.root.isDistributive) {
|
88094
|
+
return false;
|
88095
|
+
}
|
88096
|
+
if (type.root.inferTypeParameters) {
|
88097
|
+
return false;
|
88098
|
+
}
|
88099
|
+
if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
|
88100
|
+
return false;
|
88101
|
+
}
|
88102
|
+
const constraintType = getConstraintOfTypeParameter(type.checkType);
|
88103
|
+
if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
|
88104
|
+
return false;
|
88105
|
+
}
|
88106
|
+
if (!everyType(type.extendsType, (extendsType) => some(
|
88107
|
+
constraintType.types,
|
88108
|
+
(constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
|
88109
|
+
))) {
|
88110
|
+
return false;
|
88111
|
+
}
|
88112
|
+
const trueType2 = getTrueTypeFromConditionalType(type);
|
88113
|
+
const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
|
88114
|
+
if (!isValidTrueType) return false;
|
88115
|
+
const falseType2 = getFalseTypeFromConditionalType(type);
|
88116
|
+
const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
|
88117
|
+
return isValidFalseType;
|
88118
|
+
}
|
88119
|
+
function isConditionalType(type) {
|
88120
|
+
return !!(type.flags & 16777216 /* Conditional */);
|
88121
|
+
}
|
87676
88122
|
function checkWithStatement(node) {
|
87677
88123
|
if (!checkGrammarStatementInAmbientContext(node)) {
|
87678
88124
|
if (node.flags & 65536 /* AwaitContext */) {
|
@@ -97828,7 +98274,7 @@ function transformTypeScript(context) {
|
|
97828
98274
|
return updated;
|
97829
98275
|
}
|
97830
98276
|
function visitParenthesizedExpression(node) {
|
97831
|
-
const innerExpression = skipOuterExpressions(node.expression, ~(
|
98277
|
+
const innerExpression = skipOuterExpressions(node.expression, ~(38 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
|
97832
98278
|
if (isAssertionExpression(innerExpression) || isSatisfiesExpression(innerExpression)) {
|
97833
98279
|
const expression = visitNode(node.expression, visitor, isExpression);
|
97834
98280
|
Debug.assert(expression);
|
@@ -139816,9 +140262,9 @@ function mapToDisplayParts(writeDisplayParts) {
|
|
139816
140262
|
displayPartWriter.clear();
|
139817
140263
|
}
|
139818
140264
|
}
|
139819
|
-
function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags = 0 /* None
|
140265
|
+
function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags = 0 /* None */, verbosityLevel, out) {
|
139820
140266
|
return mapToDisplayParts((writer) => {
|
139821
|
-
typechecker.writeType(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer);
|
140267
|
+
typechecker.writeType(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer, verbosityLevel, out);
|
139822
140268
|
});
|
139823
140269
|
}
|
139824
140270
|
function symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration, meaning, flags = 0 /* None */) {
|
@@ -151795,7 +152241,7 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
|
|
151795
152241
|
synchronizeHostData();
|
151796
152242
|
return ts_Completions_exports.getCompletionEntrySymbol(program, log, getValidSourceFile(fileName), position, { name, source }, host, preferences);
|
151797
152243
|
}
|
151798
|
-
function getQuickInfoAtPosition(fileName, position) {
|
152244
|
+
function getQuickInfoAtPosition(fileName, position, verbosityLevel) {
|
151799
152245
|
synchronizeHostData();
|
151800
152246
|
const sourceFile = getValidSourceFile(fileName);
|
151801
152247
|
const node = getTouchingPropertyName(sourceFile, position);
|
@@ -151811,19 +152257,41 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
|
|
151811
152257
|
kind: "" /* unknown */,
|
151812
152258
|
kindModifiers: "" /* none */,
|
151813
152259
|
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
|
151814
|
-
displayParts: typeChecker.runWithCancellationToken(cancellationToken, (typeChecker2) => typeToDisplayParts(
|
152260
|
+
displayParts: typeChecker.runWithCancellationToken(cancellationToken, (typeChecker2) => typeToDisplayParts(
|
152261
|
+
typeChecker2,
|
152262
|
+
type,
|
152263
|
+
getContainerNode(nodeForQuickInfo),
|
152264
|
+
/*flags*/
|
152265
|
+
void 0,
|
152266
|
+
verbosityLevel
|
152267
|
+
)),
|
151815
152268
|
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : void 0,
|
151816
152269
|
tags: type.symbol ? type.symbol.getJsDocTags(typeChecker) : void 0
|
151817
152270
|
};
|
151818
152271
|
}
|
151819
|
-
const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(
|
152272
|
+
const { symbolKind, displayParts, documentation, tags, canIncreaseVerbosityLevel } = typeChecker.runWithCancellationToken(
|
152273
|
+
cancellationToken,
|
152274
|
+
(typeChecker2) => ts_SymbolDisplay_exports.getSymbolDisplayPartsDocumentationAndSymbolKind(
|
152275
|
+
typeChecker2,
|
152276
|
+
symbol,
|
152277
|
+
sourceFile,
|
152278
|
+
getContainerNode(nodeForQuickInfo),
|
152279
|
+
nodeForQuickInfo,
|
152280
|
+
/*semanticMeaning*/
|
152281
|
+
void 0,
|
152282
|
+
/*alias*/
|
152283
|
+
void 0,
|
152284
|
+
verbosityLevel
|
152285
|
+
)
|
152286
|
+
);
|
151820
152287
|
return {
|
151821
152288
|
kind: symbolKind,
|
151822
152289
|
kindModifiers: ts_SymbolDisplay_exports.getSymbolModifiers(typeChecker, symbol),
|
151823
152290
|
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
|
151824
152291
|
displayParts,
|
151825
152292
|
documentation,
|
151826
|
-
tags
|
152293
|
+
tags,
|
152294
|
+
canIncreaseVerbosityLevel
|
151827
152295
|
};
|
151828
152296
|
}
|
151829
152297
|
function preparePasteEditsForFile(fileName, copiedTextRange) {
|
@@ -176899,7 +177367,7 @@ function getSymbolModifiers(typeChecker, symbol) {
|
|
176899
177367
|
}
|
176900
177368
|
return modifiers.size > 0 ? arrayFrom(modifiers.values()).join(",") : "" /* none */;
|
176901
177369
|
}
|
176902
|
-
function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symbol, sourceFile, enclosingDeclaration, location, type, semanticMeaning, alias) {
|
177370
|
+
function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symbol, sourceFile, enclosingDeclaration, location, type, semanticMeaning, alias, verbosityLevel) {
|
176903
177371
|
var _a;
|
176904
177372
|
const displayParts = [];
|
176905
177373
|
let documentation = [];
|
@@ -176911,6 +177379,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
176911
177379
|
let documentationFromAlias;
|
176912
177380
|
let tagsFromAlias;
|
176913
177381
|
let hasMultipleSignatures = false;
|
177382
|
+
const typeWriterOut = verbosityLevel !== void 0 ? { couldUnfoldMore: false } : void 0;
|
176914
177383
|
if (location.kind === 110 /* ThisKeyword */ && !isThisExpression) {
|
176915
177384
|
return { displayParts: [keywordPart(110 /* ThisKeyword */)], documentation: [], symbolKind: "primitive type" /* primitiveType */, tags: void 0 };
|
176916
177385
|
}
|
@@ -177070,7 +177539,17 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177070
177539
|
displayParts.push(spacePart());
|
177071
177540
|
displayParts.push(operatorPart(64 /* EqualsToken */));
|
177072
177541
|
displayParts.push(spacePart());
|
177073
|
-
addRange(
|
177542
|
+
addRange(
|
177543
|
+
displayParts,
|
177544
|
+
typeToDisplayParts(
|
177545
|
+
typeChecker,
|
177546
|
+
location.parent && isConstTypeReference(location.parent) ? typeChecker.getTypeAtLocation(location.parent) : typeChecker.getDeclaredTypeOfSymbol(symbol),
|
177547
|
+
enclosingDeclaration,
|
177548
|
+
8388608 /* InTypeAlias */,
|
177549
|
+
verbosityLevel,
|
177550
|
+
typeWriterOut
|
177551
|
+
)
|
177552
|
+
);
|
177074
177553
|
}
|
177075
177554
|
if (symbolFlags & 384 /* Enum */) {
|
177076
177555
|
prefixNextMeaning();
|
@@ -177229,12 +177708,32 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177229
177708
|
displayParts.push(spacePart());
|
177230
177709
|
if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */ && symbolKind !== "index" /* indexSignatureElement */) {
|
177231
177710
|
const typeParameterParts = mapToDisplayParts((writer) => {
|
177232
|
-
const param = typeChecker.typeParameterToDeclaration(
|
177711
|
+
const param = typeChecker.typeParameterToDeclaration(
|
177712
|
+
type,
|
177713
|
+
enclosingDeclaration,
|
177714
|
+
symbolDisplayNodeBuilderFlags,
|
177715
|
+
/*internalFlags*/
|
177716
|
+
void 0,
|
177717
|
+
/*tracker*/
|
177718
|
+
void 0,
|
177719
|
+
verbosityLevel
|
177720
|
+
);
|
177233
177721
|
getPrinter().writeNode(4 /* Unspecified */, param, getSourceFileOfNode(getParseTreeNode(enclosingDeclaration)), writer);
|
177234
177722
|
});
|
177235
177723
|
addRange(displayParts, typeParameterParts);
|
177236
177724
|
} else {
|
177237
|
-
addRange(
|
177725
|
+
addRange(
|
177726
|
+
displayParts,
|
177727
|
+
typeToDisplayParts(
|
177728
|
+
typeChecker,
|
177729
|
+
type,
|
177730
|
+
enclosingDeclaration,
|
177731
|
+
/*flags*/
|
177732
|
+
void 0,
|
177733
|
+
verbosityLevel,
|
177734
|
+
typeWriterOut
|
177735
|
+
)
|
177736
|
+
);
|
177238
177737
|
}
|
177239
177738
|
if (isTransientSymbol(symbol) && symbol.links.target && isTransientSymbol(symbol.links.target) && symbol.links.target.links.tupleLabelDeclaration) {
|
177240
177739
|
const labelDecl = symbol.links.target.links.tupleLabelDeclaration;
|
@@ -177299,7 +177798,13 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177299
177798
|
if (tags.length === 0 && tagsFromAlias) {
|
177300
177799
|
tags = tagsFromAlias;
|
177301
177800
|
}
|
177302
|
-
return {
|
177801
|
+
return {
|
177802
|
+
displayParts,
|
177803
|
+
documentation,
|
177804
|
+
symbolKind,
|
177805
|
+
tags: tags.length === 0 ? void 0 : tags,
|
177806
|
+
canIncreaseVerbosityLevel: typeWriterOut == null ? void 0 : typeWriterOut.couldUnfoldMore
|
177807
|
+
};
|
177303
177808
|
function getPrinter() {
|
177304
177809
|
return createPrinterWithRemoveComments();
|
177305
177810
|
}
|
@@ -177412,7 +177917,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
|
|
177412
177917
|
addRange(displayParts, typeParameterParts);
|
177413
177918
|
}
|
177414
177919
|
}
|
177415
|
-
function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias) {
|
177920
|
+
function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias, verbosityLevel) {
|
177416
177921
|
return getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
|
177417
177922
|
typeChecker,
|
177418
177923
|
symbol,
|
@@ -177422,7 +177927,8 @@ function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, so
|
|
177422
177927
|
/*type*/
|
177423
177928
|
void 0,
|
177424
177929
|
semanticMeaning,
|
177425
|
-
alias
|
177930
|
+
alias,
|
177931
|
+
verbosityLevel
|
177426
177932
|
);
|
177427
177933
|
}
|
177428
177934
|
function isLocalVariableOrFunction(symbol) {
|
@@ -194365,7 +194871,7 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
|
|
194365
194871
|
getQuickInfoWorker(args, simplifiedResult) {
|
194366
194872
|
const { file, project } = this.getFileAndProject(args);
|
194367
194873
|
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file);
|
194368
|
-
const quickInfo = project.getLanguageService().getQuickInfoAtPosition(file, this.getPosition(args, scriptInfo));
|
194874
|
+
const quickInfo = project.getLanguageService().getQuickInfoAtPosition(file, this.getPosition(args, scriptInfo), args.verbosityLevel);
|
194369
194875
|
if (!quickInfo) {
|
194370
194876
|
return void 0;
|
194371
194877
|
}
|
@@ -194379,7 +194885,8 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
|
|
194379
194885
|
end: scriptInfo.positionToLineOffset(textSpanEnd(quickInfo.textSpan)),
|
194380
194886
|
displayString,
|
194381
194887
|
documentation: useDisplayParts ? this.mapDisplayParts(quickInfo.documentation, project) : displayPartsToString(quickInfo.documentation),
|
194382
|
-
tags: this.mapJSDocTagInfo(quickInfo.tags, project, useDisplayParts)
|
194888
|
+
tags: this.mapJSDocTagInfo(quickInfo.tags, project, useDisplayParts),
|
194889
|
+
canIncreaseVerbosityLevel: quickInfo.canIncreaseVerbosityLevel
|
194383
194890
|
};
|
194384
194891
|
} else {
|
194385
194892
|
return useDisplayParts ? quickInfo : {
|