@typescript-deploys/pr-build 5.7.0-pr-57718-9 → 5.8.0-pr-57838-3
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 +580 -128
- package/lib/_tsserver.js +43 -7
- package/lib/lib.decorators.d.ts +13 -15
- package/lib/lib.es2020.bigint.d.ts +2 -0
- package/lib/lib.es5.d.ts +1 -1
- package/lib/lib.esnext.d.ts +1 -0
- package/lib/lib.esnext.promise.d.ts +34 -0
- package/lib/typescript.d.ts +13 -14
- package/lib/typescript.js +783 -217
- package/package.json +1 -1
- package/lib/cancellationToken.js +0 -90
package/lib/_tsc.js
CHANGED
|
@@ -17,8 +17,8 @@ and limitations under the License.
|
|
|
17
17
|
"use strict";
|
|
18
18
|
|
|
19
19
|
// src/compiler/corePublic.ts
|
|
20
|
-
var versionMajorMinor = "5.
|
|
21
|
-
var version = `${versionMajorMinor}.0-insiders.
|
|
20
|
+
var versionMajorMinor = "5.8";
|
|
21
|
+
var version = `${versionMajorMinor}.0-insiders.20241130`;
|
|
22
22
|
|
|
23
23
|
// src/compiler/core.ts
|
|
24
24
|
var emptyArray = [];
|
|
@@ -3680,6 +3680,7 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
|
|
|
3680
3680
|
ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
|
|
3681
3681
|
ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
|
|
3682
3682
|
ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
|
|
3683
|
+
ObjectFlags3[ObjectFlags3["IsNarrowingType"] = 16777216] = "IsNarrowingType";
|
|
3683
3684
|
ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
|
|
3684
3685
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
|
|
3685
3686
|
ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
|
|
@@ -15067,7 +15068,7 @@ function tryGetModuleSpecifierFromDeclaration(node) {
|
|
|
15067
15068
|
}
|
|
15068
15069
|
}
|
|
15069
15070
|
function shouldRewriteModuleSpecifier(specifier, compilerOptions) {
|
|
15070
|
-
return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier);
|
|
15071
|
+
return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier) && hasTSFileExtension(specifier);
|
|
15071
15072
|
}
|
|
15072
15073
|
function getExternalModuleName(node) {
|
|
15073
15074
|
switch (node.kind) {
|
|
@@ -22453,6 +22454,8 @@ function createNodeFactory(flags, baseFactory2) {
|
|
|
22453
22454
|
node.colonToken = colonToken ?? createToken(59 /* ColonToken */);
|
|
22454
22455
|
node.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse);
|
|
22455
22456
|
node.transformFlags |= propagateChildFlags(node.condition) | propagateChildFlags(node.questionToken) | propagateChildFlags(node.whenTrue) | propagateChildFlags(node.colonToken) | propagateChildFlags(node.whenFalse);
|
|
22457
|
+
node.flowNodeWhenFalse = void 0;
|
|
22458
|
+
node.flowNodeWhenTrue = void 0;
|
|
22456
22459
|
return node;
|
|
22457
22460
|
}
|
|
22458
22461
|
function updateConditionalExpression(node, condition, questionToken, whenTrue, colonToken, whenFalse) {
|
|
@@ -24256,7 +24259,7 @@ function createNodeFactory(flags, baseFactory2) {
|
|
|
24256
24259
|
function isIgnorableParen(node) {
|
|
24257
24260
|
return isParenthesizedExpression(node) && nodeIsSynthesized(node) && nodeIsSynthesized(getSourceMapRange(node)) && nodeIsSynthesized(getCommentRange(node)) && !some(getSyntheticLeadingComments(node)) && !some(getSyntheticTrailingComments(node));
|
|
24258
24261
|
}
|
|
24259
|
-
function restoreOuterExpressions(outerExpression, innerExpression, kinds =
|
|
24262
|
+
function restoreOuterExpressions(outerExpression, innerExpression, kinds = 63 /* All */) {
|
|
24260
24263
|
if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
|
|
24261
24264
|
return updateOuterExpression(
|
|
24262
24265
|
outerExpression,
|
|
@@ -24302,7 +24305,7 @@ function createNodeFactory(flags, baseFactory2) {
|
|
|
24302
24305
|
}
|
|
24303
24306
|
}
|
|
24304
24307
|
function createCallBinding(expression, recordTempVariable, languageVersion, cacheIdentifiers = false) {
|
|
24305
|
-
const callee = skipOuterExpressions(expression,
|
|
24308
|
+
const callee = skipOuterExpressions(expression, 63 /* All */);
|
|
24306
24309
|
let thisArg;
|
|
24307
24310
|
let target;
|
|
24308
24311
|
if (isSuperProperty(callee)) {
|
|
@@ -27171,7 +27174,7 @@ function getJSDocTypeAssertionType(node) {
|
|
|
27171
27174
|
Debug.assertIsDefined(type);
|
|
27172
27175
|
return type;
|
|
27173
27176
|
}
|
|
27174
|
-
function isOuterExpression(node, kinds =
|
|
27177
|
+
function isOuterExpression(node, kinds = 63 /* All */) {
|
|
27175
27178
|
switch (node.kind) {
|
|
27176
27179
|
case 217 /* ParenthesizedExpression */:
|
|
27177
27180
|
if (kinds & -2147483648 /* ExcludeJSDocTypeAssertion */ && isJSDocTypeAssertion(node)) {
|
|
@@ -27180,8 +27183,9 @@ function isOuterExpression(node, kinds = 31 /* All */) {
|
|
|
27180
27183
|
return (kinds & 1 /* Parentheses */) !== 0;
|
|
27181
27184
|
case 216 /* TypeAssertionExpression */:
|
|
27182
27185
|
case 234 /* AsExpression */:
|
|
27183
|
-
case 238 /* SatisfiesExpression */:
|
|
27184
27186
|
return (kinds & 2 /* TypeAssertions */) !== 0;
|
|
27187
|
+
case 238 /* SatisfiesExpression */:
|
|
27188
|
+
return (kinds & (2 /* TypeAssertions */ | 32 /* Satisfies */)) !== 0;
|
|
27185
27189
|
case 233 /* ExpressionWithTypeArguments */:
|
|
27186
27190
|
return (kinds & 16 /* ExpressionsWithTypeArguments */) !== 0;
|
|
27187
27191
|
case 235 /* NonNullExpression */:
|
|
@@ -27191,13 +27195,13 @@ function isOuterExpression(node, kinds = 31 /* All */) {
|
|
|
27191
27195
|
}
|
|
27192
27196
|
return false;
|
|
27193
27197
|
}
|
|
27194
|
-
function skipOuterExpressions(node, kinds =
|
|
27198
|
+
function skipOuterExpressions(node, kinds = 63 /* All */) {
|
|
27195
27199
|
while (isOuterExpression(node, kinds)) {
|
|
27196
27200
|
node = node.expression;
|
|
27197
27201
|
}
|
|
27198
27202
|
return node;
|
|
27199
27203
|
}
|
|
27200
|
-
function walkUpOuterExpressions(node, kinds =
|
|
27204
|
+
function walkUpOuterExpressions(node, kinds = 63 /* All */) {
|
|
27201
27205
|
let parent = node.parent;
|
|
27202
27206
|
while (isOuterExpression(parent, kinds)) {
|
|
27203
27207
|
parent = parent.parent;
|
|
@@ -36099,6 +36103,7 @@ var libEntries = [
|
|
|
36099
36103
|
["esnext.regexp", "lib.es2024.regexp.d.ts"],
|
|
36100
36104
|
["esnext.string", "lib.es2024.string.d.ts"],
|
|
36101
36105
|
["esnext.iterator", "lib.esnext.iterator.d.ts"],
|
|
36106
|
+
["esnext.promise", "lib.esnext.promise.d.ts"],
|
|
36102
36107
|
["decorators", "lib.decorators.d.ts"],
|
|
36103
36108
|
["decorators.legacy", "lib.decorators.legacy.d.ts"]
|
|
36104
36109
|
];
|
|
@@ -41908,6 +41913,7 @@ function createBinder() {
|
|
|
41908
41913
|
var preSwitchCaseFlow;
|
|
41909
41914
|
var activeLabelList;
|
|
41910
41915
|
var hasExplicitReturn;
|
|
41916
|
+
var inReturnPosition;
|
|
41911
41917
|
var hasFlowEffects;
|
|
41912
41918
|
var emitFlags;
|
|
41913
41919
|
var inStrictMode;
|
|
@@ -41980,6 +41986,7 @@ function createBinder() {
|
|
|
41980
41986
|
currentExceptionTarget = void 0;
|
|
41981
41987
|
activeLabelList = void 0;
|
|
41982
41988
|
hasExplicitReturn = false;
|
|
41989
|
+
inReturnPosition = false;
|
|
41983
41990
|
hasFlowEffects = false;
|
|
41984
41991
|
inAssignmentPattern = false;
|
|
41985
41992
|
emitFlags = 0 /* None */;
|
|
@@ -42216,6 +42223,8 @@ function createBinder() {
|
|
|
42216
42223
|
const saveContainer = container;
|
|
42217
42224
|
const saveThisParentContainer = thisParentContainer;
|
|
42218
42225
|
const savedBlockScopeContainer = blockScopeContainer;
|
|
42226
|
+
const savedInReturnPosition = inReturnPosition;
|
|
42227
|
+
if (node.kind === 219 /* ArrowFunction */ && node.body.kind !== 241 /* Block */) inReturnPosition = true;
|
|
42219
42228
|
if (containerFlags & 1 /* IsContainer */) {
|
|
42220
42229
|
if (node.kind !== 219 /* ArrowFunction */) {
|
|
42221
42230
|
thisParentContainer = container;
|
|
@@ -42293,6 +42302,7 @@ function createBinder() {
|
|
|
42293
42302
|
} else {
|
|
42294
42303
|
bindChildren(node);
|
|
42295
42304
|
}
|
|
42305
|
+
inReturnPosition = savedInReturnPosition;
|
|
42296
42306
|
container = saveContainer;
|
|
42297
42307
|
thisParentContainer = saveThisParentContainer;
|
|
42298
42308
|
blockScopeContainer = savedBlockScopeContainer;
|
|
@@ -42744,7 +42754,10 @@ function createBinder() {
|
|
|
42744
42754
|
currentFlow = finishFlowLabel(postIfLabel);
|
|
42745
42755
|
}
|
|
42746
42756
|
function bindReturnOrThrow(node) {
|
|
42757
|
+
const savedInReturnPosition = inReturnPosition;
|
|
42758
|
+
inReturnPosition = true;
|
|
42747
42759
|
bind(node.expression);
|
|
42760
|
+
inReturnPosition = savedInReturnPosition;
|
|
42748
42761
|
if (node.kind === 253 /* ReturnStatement */) {
|
|
42749
42762
|
hasExplicitReturn = true;
|
|
42750
42763
|
if (currentReturnTarget) {
|
|
@@ -43105,10 +43118,16 @@ function createBinder() {
|
|
|
43105
43118
|
hasFlowEffects = false;
|
|
43106
43119
|
bindCondition(node.condition, trueLabel, falseLabel);
|
|
43107
43120
|
currentFlow = finishFlowLabel(trueLabel);
|
|
43121
|
+
if (inReturnPosition) {
|
|
43122
|
+
node.flowNodeWhenTrue = currentFlow;
|
|
43123
|
+
}
|
|
43108
43124
|
bind(node.questionToken);
|
|
43109
43125
|
bind(node.whenTrue);
|
|
43110
43126
|
addAntecedent(postExpressionLabel, currentFlow);
|
|
43111
43127
|
currentFlow = finishFlowLabel(falseLabel);
|
|
43128
|
+
if (inReturnPosition) {
|
|
43129
|
+
node.flowNodeWhenFalse = currentFlow;
|
|
43130
|
+
}
|
|
43112
43131
|
bind(node.colonToken);
|
|
43113
43132
|
bind(node.whenFalse);
|
|
43114
43133
|
addAntecedent(postExpressionLabel, currentFlow);
|
|
@@ -46165,8 +46184,8 @@ function createTypeChecker(host) {
|
|
|
46165
46184
|
writeSignature: (signature, enclosingDeclaration, flags, kind, writer) => {
|
|
46166
46185
|
return signatureToString(signature, getParseTreeNode(enclosingDeclaration), flags, kind, writer);
|
|
46167
46186
|
},
|
|
46168
|
-
writeType: (type, enclosingDeclaration, flags, writer) => {
|
|
46169
|
-
return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer);
|
|
46187
|
+
writeType: (type, enclosingDeclaration, flags, writer, verbosityLevel, out) => {
|
|
46188
|
+
return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer, verbosityLevel, out);
|
|
46170
46189
|
},
|
|
46171
46190
|
writeSymbol: (symbol, enclosingDeclaration, meaning, flags, writer) => {
|
|
46172
46191
|
return symbolToString(symbol, getParseTreeNode(enclosingDeclaration), meaning, flags, writer);
|
|
@@ -46952,6 +46971,7 @@ function createTypeChecker(host) {
|
|
|
46952
46971
|
[".jsx", ".jsx"],
|
|
46953
46972
|
[".json", ".json"]
|
|
46954
46973
|
];
|
|
46974
|
+
var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
|
|
46955
46975
|
initializeTypeChecker();
|
|
46956
46976
|
return checker;
|
|
46957
46977
|
function isDefinitelyReferenceToGlobalSymbolObject(node) {
|
|
@@ -47815,9 +47835,9 @@ function createTypeChecker(host) {
|
|
|
47815
47835
|
const containerKind = grandparent.parent.kind;
|
|
47816
47836
|
if (containerKind === 264 /* InterfaceDeclaration */ && heritageKind === 96 /* ExtendsKeyword */) {
|
|
47817
47837
|
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
|
|
47818
|
-
} else if (
|
|
47838
|
+
} else if (isClassLike(grandparent.parent) && heritageKind === 96 /* ExtendsKeyword */) {
|
|
47819
47839
|
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
|
|
47820
|
-
} else if (
|
|
47840
|
+
} else if (isClassLike(grandparent.parent) && heritageKind === 119 /* ImplementsKeyword */) {
|
|
47821
47841
|
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
|
|
47822
47842
|
}
|
|
47823
47843
|
} else {
|
|
@@ -49690,7 +49710,7 @@ function createTypeChecker(host) {
|
|
|
49690
49710
|
const links = getSymbolLinks(symbol);
|
|
49691
49711
|
const cache = links.accessibleChainCache || (links.accessibleChainCache = /* @__PURE__ */ new Map());
|
|
49692
49712
|
const firstRelevantLocation = forEachSymbolTableInScope(enclosingDeclaration, (_, __, ___, node) => node);
|
|
49693
|
-
const key = `${useOnlyExternalAliasing ? 0 : 1}|${firstRelevantLocation
|
|
49713
|
+
const key = `${useOnlyExternalAliasing ? 0 : 1}|${firstRelevantLocation ? getNodeId(firstRelevantLocation) : 0}|${meaning}`;
|
|
49694
49714
|
if (cache.has(key)) {
|
|
49695
49715
|
return cache.get(key);
|
|
49696
49716
|
}
|
|
@@ -50087,14 +50107,18 @@ function createTypeChecker(host) {
|
|
|
50087
50107
|
return writer2;
|
|
50088
50108
|
}
|
|
50089
50109
|
}
|
|
50090
|
-
function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter("")) {
|
|
50091
|
-
const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation
|
|
50110
|
+
function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter(""), verbosityLevel, out) {
|
|
50111
|
+
const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */ || verbosityLevel !== void 0;
|
|
50092
50112
|
const typeNode = nodeBuilder.typeToTypeNode(
|
|
50093
50113
|
type,
|
|
50094
50114
|
enclosingDeclaration,
|
|
50095
|
-
toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0
|
|
50115
|
+
toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0),
|
|
50096
50116
|
/*internalFlags*/
|
|
50097
|
-
void 0
|
|
50117
|
+
void 0,
|
|
50118
|
+
/*tracker*/
|
|
50119
|
+
void 0,
|
|
50120
|
+
verbosityLevel,
|
|
50121
|
+
out
|
|
50098
50122
|
);
|
|
50099
50123
|
if (typeNode === void 0) return Debug.fail("should always get typenode");
|
|
50100
50124
|
const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
|
|
@@ -50234,12 +50258,7 @@ function createTypeChecker(host) {
|
|
|
50234
50258
|
enterNewScope(context, node) {
|
|
50235
50259
|
if (isFunctionLike(node) || isJSDocSignature(node)) {
|
|
50236
50260
|
const signature = getSignatureFromDeclaration(node);
|
|
50237
|
-
|
|
50238
|
-
signature,
|
|
50239
|
-
/*skipUnionExpanding*/
|
|
50240
|
-
true
|
|
50241
|
-
)[0];
|
|
50242
|
-
return enterNewScope(context, node, expandedParams, signature.typeParameters);
|
|
50261
|
+
return enterNewScope(context, node, signature.parameters, signature.typeParameters);
|
|
50243
50262
|
} else {
|
|
50244
50263
|
const typeParameters = isConditionalTypeNode(node) ? getInferTypeParameters(node) : [getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node.typeParameter))];
|
|
50245
50264
|
return enterNewScope(
|
|
@@ -50326,31 +50345,127 @@ function createTypeChecker(host) {
|
|
|
50326
50345
|
};
|
|
50327
50346
|
return {
|
|
50328
50347
|
syntacticBuilderResolver,
|
|
50329
|
-
typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
|
|
50330
|
-
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50331
|
-
|
|
50332
|
-
|
|
50333
|
-
|
|
50334
|
-
|
|
50335
|
-
|
|
50336
|
-
|
|
50337
|
-
|
|
50338
|
-
|
|
50339
|
-
)
|
|
50340
|
-
|
|
50341
|
-
|
|
50342
|
-
|
|
50343
|
-
|
|
50344
|
-
|
|
50345
|
-
|
|
50346
|
-
|
|
50347
|
-
)
|
|
50348
|
-
|
|
50349
|
-
|
|
50350
|
-
|
|
50351
|
-
|
|
50352
|
-
|
|
50353
|
-
|
|
50348
|
+
typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeToTypeNodeHelper(type, context), out),
|
|
50349
|
+
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50350
|
+
enclosingDeclaration,
|
|
50351
|
+
flags,
|
|
50352
|
+
internalFlags,
|
|
50353
|
+
tracker,
|
|
50354
|
+
/*verbosityLevel*/
|
|
50355
|
+
void 0,
|
|
50356
|
+
(context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)
|
|
50357
|
+
),
|
|
50358
|
+
serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50359
|
+
enclosingDeclaration,
|
|
50360
|
+
flags,
|
|
50361
|
+
internalFlags,
|
|
50362
|
+
tracker,
|
|
50363
|
+
/*verbosityLevel*/
|
|
50364
|
+
void 0,
|
|
50365
|
+
(context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)
|
|
50366
|
+
),
|
|
50367
|
+
serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50368
|
+
enclosingDeclaration,
|
|
50369
|
+
flags,
|
|
50370
|
+
internalFlags,
|
|
50371
|
+
tracker,
|
|
50372
|
+
/*verbosityLevel*/
|
|
50373
|
+
void 0,
|
|
50374
|
+
(context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)
|
|
50375
|
+
),
|
|
50376
|
+
serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50377
|
+
enclosingDeclaration,
|
|
50378
|
+
flags,
|
|
50379
|
+
internalFlags,
|
|
50380
|
+
tracker,
|
|
50381
|
+
/*verbosityLevel*/
|
|
50382
|
+
void 0,
|
|
50383
|
+
(context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)
|
|
50384
|
+
),
|
|
50385
|
+
indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50386
|
+
enclosingDeclaration,
|
|
50387
|
+
flags,
|
|
50388
|
+
internalFlags,
|
|
50389
|
+
tracker,
|
|
50390
|
+
/*verbosityLevel*/
|
|
50391
|
+
void 0,
|
|
50392
|
+
(context) => indexInfoToIndexSignatureDeclarationHelper(
|
|
50393
|
+
indexInfo,
|
|
50394
|
+
context,
|
|
50395
|
+
/*typeNode*/
|
|
50396
|
+
void 0
|
|
50397
|
+
)
|
|
50398
|
+
),
|
|
50399
|
+
signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50400
|
+
enclosingDeclaration,
|
|
50401
|
+
flags,
|
|
50402
|
+
internalFlags,
|
|
50403
|
+
tracker,
|
|
50404
|
+
/*verbosityLevel*/
|
|
50405
|
+
void 0,
|
|
50406
|
+
(context) => signatureToSignatureDeclarationHelper(signature, kind, context)
|
|
50407
|
+
),
|
|
50408
|
+
symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50409
|
+
enclosingDeclaration,
|
|
50410
|
+
flags,
|
|
50411
|
+
internalFlags,
|
|
50412
|
+
tracker,
|
|
50413
|
+
/*verbosityLevel*/
|
|
50414
|
+
void 0,
|
|
50415
|
+
(context) => symbolToName(
|
|
50416
|
+
symbol,
|
|
50417
|
+
context,
|
|
50418
|
+
meaning,
|
|
50419
|
+
/*expectsIdentifier*/
|
|
50420
|
+
false
|
|
50421
|
+
)
|
|
50422
|
+
),
|
|
50423
|
+
symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50424
|
+
enclosingDeclaration,
|
|
50425
|
+
flags,
|
|
50426
|
+
internalFlags,
|
|
50427
|
+
tracker,
|
|
50428
|
+
/*verbosityLevel*/
|
|
50429
|
+
void 0,
|
|
50430
|
+
(context) => symbolToExpression(symbol, context, meaning)
|
|
50431
|
+
),
|
|
50432
|
+
symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50433
|
+
enclosingDeclaration,
|
|
50434
|
+
flags,
|
|
50435
|
+
internalFlags,
|
|
50436
|
+
tracker,
|
|
50437
|
+
/*verbosityLevel*/
|
|
50438
|
+
void 0,
|
|
50439
|
+
(context) => typeParametersToTypeParameterDeclarations(symbol, context)
|
|
50440
|
+
),
|
|
50441
|
+
symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50442
|
+
enclosingDeclaration,
|
|
50443
|
+
flags,
|
|
50444
|
+
internalFlags,
|
|
50445
|
+
tracker,
|
|
50446
|
+
/*verbosityLevel*/
|
|
50447
|
+
void 0,
|
|
50448
|
+
(context) => symbolToParameterDeclaration(symbol, context)
|
|
50449
|
+
),
|
|
50450
|
+
typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeParameterToDeclaration(parameter, context)),
|
|
50451
|
+
symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50452
|
+
enclosingDeclaration,
|
|
50453
|
+
flags,
|
|
50454
|
+
internalFlags,
|
|
50455
|
+
tracker,
|
|
50456
|
+
/*verbosityLevel*/
|
|
50457
|
+
void 0,
|
|
50458
|
+
(context) => symbolTableToDeclarationStatements(symbolTable, context)
|
|
50459
|
+
),
|
|
50460
|
+
symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
|
|
50461
|
+
enclosingDeclaration,
|
|
50462
|
+
flags,
|
|
50463
|
+
internalFlags,
|
|
50464
|
+
tracker,
|
|
50465
|
+
/*verbosityLevel*/
|
|
50466
|
+
void 0,
|
|
50467
|
+
(context) => symbolToNode(symbol, context, meaning)
|
|
50468
|
+
)
|
|
50354
50469
|
};
|
|
50355
50470
|
function getTypeFromTypeNode2(context, node, noMappedTypes) {
|
|
50356
50471
|
const type = getTypeFromTypeNodeWithoutContext(node);
|
|
@@ -50392,7 +50507,7 @@ function createTypeChecker(host) {
|
|
|
50392
50507
|
}
|
|
50393
50508
|
return symbolToExpression(symbol, context, meaning);
|
|
50394
50509
|
}
|
|
50395
|
-
function withContext(enclosingDeclaration, flags, internalFlags, tracker, cb) {
|
|
50510
|
+
function withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, cb, out) {
|
|
50396
50511
|
const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : (internalFlags || 0 /* None */) & 4 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
|
|
50397
50512
|
const context = {
|
|
50398
50513
|
enclosingDeclaration,
|
|
@@ -50400,6 +50515,7 @@ function createTypeChecker(host) {
|
|
|
50400
50515
|
flags: flags || 0 /* None */,
|
|
50401
50516
|
internalFlags: internalFlags || 0 /* None */,
|
|
50402
50517
|
tracker: void 0,
|
|
50518
|
+
unfoldDepth: verbosityLevel ?? -1,
|
|
50403
50519
|
encounteredError: false,
|
|
50404
50520
|
suppressReportInferenceFallback: false,
|
|
50405
50521
|
reportedDiagnostic: false,
|
|
@@ -50421,13 +50537,18 @@ function createTypeChecker(host) {
|
|
|
50421
50537
|
typeParameterNamesByText: void 0,
|
|
50422
50538
|
typeParameterNamesByTextNextNameCount: void 0,
|
|
50423
50539
|
enclosingSymbolTypes: /* @__PURE__ */ new Map(),
|
|
50424
|
-
mapper: void 0
|
|
50540
|
+
mapper: void 0,
|
|
50541
|
+
depth: 0,
|
|
50542
|
+
couldUnfoldMore: false
|
|
50425
50543
|
};
|
|
50426
50544
|
context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
|
|
50427
50545
|
const resultingNode = cb(context);
|
|
50428
50546
|
if (context.truncating && context.flags & 1 /* NoTruncation */) {
|
|
50429
50547
|
context.tracker.reportTruncationError();
|
|
50430
50548
|
}
|
|
50549
|
+
if (out) {
|
|
50550
|
+
out.couldUnfoldMore = context.couldUnfoldMore;
|
|
50551
|
+
}
|
|
50431
50552
|
return context.encounteredError ? void 0 : resultingNode;
|
|
50432
50553
|
}
|
|
50433
50554
|
function addSymbolTypeToContext(context, symbol, type) {
|
|
@@ -50446,16 +50567,36 @@ function createTypeChecker(host) {
|
|
|
50446
50567
|
function saveRestoreFlags(context) {
|
|
50447
50568
|
const flags = context.flags;
|
|
50448
50569
|
const internalFlags = context.internalFlags;
|
|
50570
|
+
const depth = context.depth;
|
|
50449
50571
|
return restore;
|
|
50450
50572
|
function restore() {
|
|
50451
50573
|
context.flags = flags;
|
|
50452
50574
|
context.internalFlags = internalFlags;
|
|
50575
|
+
context.depth = depth;
|
|
50453
50576
|
}
|
|
50454
50577
|
}
|
|
50455
50578
|
function checkTruncationLength(context) {
|
|
50456
50579
|
if (context.truncating) return context.truncating;
|
|
50457
50580
|
return context.truncating = context.approximateLength > (context.flags & 1 /* NoTruncation */ ? noTruncationMaximumTruncationLength : defaultMaximumTruncationLength);
|
|
50458
50581
|
}
|
|
50582
|
+
function couldUnfoldType(type, context) {
|
|
50583
|
+
var _a;
|
|
50584
|
+
if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
|
|
50585
|
+
return false;
|
|
50586
|
+
}
|
|
50587
|
+
return context.depth < context.unfoldDepth || context.depth === context.unfoldDepth && !context.couldUnfoldMore;
|
|
50588
|
+
}
|
|
50589
|
+
function canUnfoldType(type, context) {
|
|
50590
|
+
var _a;
|
|
50591
|
+
if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
|
|
50592
|
+
return false;
|
|
50593
|
+
}
|
|
50594
|
+
const result = context.depth < context.unfoldDepth;
|
|
50595
|
+
if (!result) {
|
|
50596
|
+
context.couldUnfoldMore = true;
|
|
50597
|
+
}
|
|
50598
|
+
return result;
|
|
50599
|
+
}
|
|
50459
50600
|
function typeToTypeNodeHelper(type, context) {
|
|
50460
50601
|
const restoreFlags = saveRestoreFlags(context);
|
|
50461
50602
|
const typeNode = typeToTypeNodeWorker(type, context);
|
|
@@ -50603,16 +50744,27 @@ function createTypeChecker(host) {
|
|
|
50603
50744
|
return factory.createThisTypeNode();
|
|
50604
50745
|
}
|
|
50605
50746
|
if (!inTypeAlias && type.aliasSymbol && (context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */ || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) {
|
|
50606
|
-
|
|
50607
|
-
|
|
50608
|
-
|
|
50609
|
-
|
|
50747
|
+
if (!canUnfoldType(type, context)) {
|
|
50748
|
+
const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
|
|
50749
|
+
if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
|
|
50750
|
+
if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
|
|
50751
|
+
return factory.createArrayTypeNode(typeArgumentNodes[0]);
|
|
50752
|
+
}
|
|
50753
|
+
return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
|
|
50610
50754
|
}
|
|
50611
|
-
|
|
50755
|
+
context.depth += 1;
|
|
50612
50756
|
}
|
|
50613
50757
|
const objectFlags = getObjectFlags(type);
|
|
50614
50758
|
if (objectFlags & 4 /* Reference */) {
|
|
50615
50759
|
Debug.assert(!!(type.flags & 524288 /* Object */));
|
|
50760
|
+
if (canUnfoldType(type, context)) {
|
|
50761
|
+
context.depth += 1;
|
|
50762
|
+
return createAnonymousTypeNode(
|
|
50763
|
+
type,
|
|
50764
|
+
/*forceClassExpansion*/
|
|
50765
|
+
true
|
|
50766
|
+
);
|
|
50767
|
+
}
|
|
50616
50768
|
return type.node ? visitAndTransformType(type, typeReferenceToTypeNode) : typeReferenceToTypeNode(type);
|
|
50617
50769
|
}
|
|
50618
50770
|
if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
|
|
@@ -50642,6 +50794,14 @@ function createTypeChecker(host) {
|
|
|
50642
50794
|
void 0
|
|
50643
50795
|
);
|
|
50644
50796
|
}
|
|
50797
|
+
if (objectFlags & 3 /* ClassOrInterface */ && canUnfoldType(type, context)) {
|
|
50798
|
+
context.depth += 1;
|
|
50799
|
+
return createAnonymousTypeNode(
|
|
50800
|
+
type,
|
|
50801
|
+
/*forceClassExpansion*/
|
|
50802
|
+
true
|
|
50803
|
+
);
|
|
50804
|
+
}
|
|
50645
50805
|
if (type.symbol) {
|
|
50646
50806
|
return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
|
|
50647
50807
|
}
|
|
@@ -50845,7 +51005,7 @@ function createTypeChecker(host) {
|
|
|
50845
51005
|
}
|
|
50846
51006
|
return result;
|
|
50847
51007
|
}
|
|
50848
|
-
function createAnonymousTypeNode(type2) {
|
|
51008
|
+
function createAnonymousTypeNode(type2, forceClassExpansion = false) {
|
|
50849
51009
|
var _a2, _b2;
|
|
50850
51010
|
const typeId = type2.id;
|
|
50851
51011
|
const symbol = type2.symbol;
|
|
@@ -50868,7 +51028,7 @@ function createTypeChecker(host) {
|
|
|
50868
51028
|
const isInstanceType = isClassInstanceSide(type2) ? 788968 /* Type */ : 111551 /* Value */;
|
|
50869
51029
|
if (isJSConstructor(symbol.valueDeclaration)) {
|
|
50870
51030
|
return symbolToTypeNode(symbol, context, isInstanceType);
|
|
50871
|
-
} else if (symbol.flags & 32 /* Class */ && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
|
|
51031
|
+
} else if (symbol.flags & 32 /* Class */ && !forceClassExpansion && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
|
|
50872
51032
|
symbol,
|
|
50873
51033
|
context.enclosingDeclaration,
|
|
50874
51034
|
isInstanceType,
|
|
@@ -50912,7 +51072,7 @@ function createTypeChecker(host) {
|
|
|
50912
51072
|
if (id && !context.symbolDepth) {
|
|
50913
51073
|
context.symbolDepth = /* @__PURE__ */ new Map();
|
|
50914
51074
|
}
|
|
50915
|
-
const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
|
|
51075
|
+
const links = context.unfoldDepth >= 0 ? void 0 : context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
|
|
50916
51076
|
const key = `${getTypeId(type2)}|${context.flags}|${context.internalFlags}`;
|
|
50917
51077
|
if (links) {
|
|
50918
51078
|
links.serializedTypes || (links.serializedTypes = /* @__PURE__ */ new Map());
|
|
@@ -51827,7 +51987,7 @@ function createTypeChecker(host) {
|
|
|
51827
51987
|
return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
|
|
51828
51988
|
}
|
|
51829
51989
|
function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
|
|
51830
|
-
return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
|
|
51990
|
+
return !couldUnfoldType(type, context) && typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
|
|
51831
51991
|
}
|
|
51832
51992
|
function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
|
|
51833
51993
|
const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
|
|
@@ -52461,7 +52621,7 @@ function createTypeChecker(host) {
|
|
|
52461
52621
|
let result;
|
|
52462
52622
|
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
|
|
52463
52623
|
const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
|
|
52464
|
-
if (decl) {
|
|
52624
|
+
if (!couldUnfoldType(type, context) && decl) {
|
|
52465
52625
|
if (isAccessor(decl)) {
|
|
52466
52626
|
result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
|
|
52467
52627
|
} else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
|
|
@@ -55256,7 +55416,6 @@ function createTypeChecker(host) {
|
|
|
55256
55416
|
const flags = 4 /* Property */ | (e.initializer ? 16777216 /* Optional */ : 0);
|
|
55257
55417
|
const symbol = createSymbol(flags, text);
|
|
55258
55418
|
symbol.links.type = getTypeFromBindingElement(e, includePatternInType, reportErrors2);
|
|
55259
|
-
symbol.links.bindingElement = e;
|
|
55260
55419
|
members.set(symbol.escapedName, symbol);
|
|
55261
55420
|
});
|
|
55262
55421
|
const result = createAnonymousType(
|
|
@@ -59184,11 +59343,14 @@ function createTypeChecker(host) {
|
|
|
59184
59343
|
function isNoInferType(type) {
|
|
59185
59344
|
return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
|
|
59186
59345
|
}
|
|
59187
|
-
function
|
|
59188
|
-
return
|
|
59346
|
+
function isNarrowingSubstitutionType(type) {
|
|
59347
|
+
return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
|
|
59348
|
+
}
|
|
59349
|
+
function getSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59350
|
+
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
|
|
59189
59351
|
}
|
|
59190
|
-
function getOrCreateSubstitutionType(baseType, constraint) {
|
|
59191
|
-
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
|
|
59352
|
+
function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59353
|
+
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
|
|
59192
59354
|
const cached = substitutionTypes.get(id);
|
|
59193
59355
|
if (cached) {
|
|
59194
59356
|
return cached;
|
|
@@ -59196,6 +59358,9 @@ function createTypeChecker(host) {
|
|
|
59196
59358
|
const result = createType(33554432 /* Substitution */);
|
|
59197
59359
|
result.baseType = baseType;
|
|
59198
59360
|
result.constraint = constraint;
|
|
59361
|
+
if (isNarrowed) {
|
|
59362
|
+
result.objectFlags |= 16777216 /* IsNarrowingType */;
|
|
59363
|
+
}
|
|
59199
59364
|
substitutionTypes.set(id, result);
|
|
59200
59365
|
return result;
|
|
59201
59366
|
}
|
|
@@ -61398,7 +61563,7 @@ function createTypeChecker(host) {
|
|
|
61398
61563
|
function isDeferredType(type, checkTuples) {
|
|
61399
61564
|
return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
|
|
61400
61565
|
}
|
|
61401
|
-
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
|
|
61566
|
+
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
|
|
61402
61567
|
let result;
|
|
61403
61568
|
let extraTypes;
|
|
61404
61569
|
let tailCount = 0;
|
|
@@ -61415,10 +61580,11 @@ function createTypeChecker(host) {
|
|
|
61415
61580
|
if (checkType === wildcardType || extendsType === wildcardType) {
|
|
61416
61581
|
return wildcardType;
|
|
61417
61582
|
}
|
|
61583
|
+
const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
|
|
61418
61584
|
const checkTypeNode = skipTypeParentheses(root.node.checkType);
|
|
61419
61585
|
const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
|
|
61420
61586
|
const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
|
|
61421
|
-
const checkTypeDeferred = isDeferredType(
|
|
61587
|
+
const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
|
|
61422
61588
|
let combinedMapper;
|
|
61423
61589
|
if (root.inferTypeParameters) {
|
|
61424
61590
|
const context = createInferenceContext(
|
|
@@ -61437,8 +61603,8 @@ function createTypeChecker(host) {
|
|
|
61437
61603
|
}
|
|
61438
61604
|
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
|
|
61439
61605
|
if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
|
|
61440
|
-
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (
|
|
61441
|
-
if (
|
|
61606
|
+
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
|
|
61607
|
+
if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
|
|
61442
61608
|
(extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
|
|
61443
61609
|
}
|
|
61444
61610
|
const falseType2 = getTypeFromTypeNode(root.node.falseType);
|
|
@@ -61455,7 +61621,7 @@ function createTypeChecker(host) {
|
|
|
61455
61621
|
result = instantiateType(falseType2, mapper);
|
|
61456
61622
|
break;
|
|
61457
61623
|
}
|
|
61458
|
-
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(
|
|
61624
|
+
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
|
|
61459
61625
|
const trueType2 = getTypeFromTypeNode(root.node.trueType);
|
|
61460
61626
|
const trueMapper = combinedMapper || mapper;
|
|
61461
61627
|
if (canTailRecurse(trueType2, trueMapper)) {
|
|
@@ -62421,8 +62587,39 @@ function createTypeChecker(host) {
|
|
|
62421
62587
|
if (!result) {
|
|
62422
62588
|
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
|
|
62423
62589
|
const checkType = root.checkType;
|
|
62424
|
-
|
|
62425
|
-
|
|
62590
|
+
let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
|
|
62591
|
+
let narrowingBaseType;
|
|
62592
|
+
const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
|
|
62593
|
+
if (forNarrowing) {
|
|
62594
|
+
narrowingBaseType = distributionType.baseType;
|
|
62595
|
+
distributionType = getReducedType(distributionType.constraint);
|
|
62596
|
+
}
|
|
62597
|
+
if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
|
|
62598
|
+
if (narrowingBaseType) {
|
|
62599
|
+
result = mapTypeToIntersection(
|
|
62600
|
+
distributionType,
|
|
62601
|
+
(t) => getConditionalType(
|
|
62602
|
+
root,
|
|
62603
|
+
prependTypeMapping(checkType, getSubstitutionType(
|
|
62604
|
+
narrowingBaseType,
|
|
62605
|
+
t,
|
|
62606
|
+
/*isNarrowed*/
|
|
62607
|
+
true
|
|
62608
|
+
), newMapper),
|
|
62609
|
+
forConstraint,
|
|
62610
|
+
/*aliasSymbol*/
|
|
62611
|
+
void 0,
|
|
62612
|
+
/*aliasTypeArguments*/
|
|
62613
|
+
void 0,
|
|
62614
|
+
forNarrowing
|
|
62615
|
+
)
|
|
62616
|
+
);
|
|
62617
|
+
} else {
|
|
62618
|
+
result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
|
|
62619
|
+
}
|
|
62620
|
+
} else {
|
|
62621
|
+
result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
|
|
62622
|
+
}
|
|
62426
62623
|
root.instantiations.set(id, result);
|
|
62427
62624
|
}
|
|
62428
62625
|
return result;
|
|
@@ -63565,10 +63762,12 @@ function createTypeChecker(host) {
|
|
|
63565
63762
|
function shouldNormalizeIntersection(type) {
|
|
63566
63763
|
let hasInstantiable = false;
|
|
63567
63764
|
let hasNullableOrEmpty = false;
|
|
63765
|
+
let hasSubstitution = false;
|
|
63568
63766
|
for (const t of type.types) {
|
|
63569
63767
|
hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
|
|
63570
63768
|
hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
|
|
63571
|
-
|
|
63769
|
+
hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
|
|
63770
|
+
if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
|
|
63572
63771
|
}
|
|
63573
63772
|
return false;
|
|
63574
63773
|
}
|
|
@@ -64660,15 +64859,15 @@ function createTypeChecker(host) {
|
|
|
64660
64859
|
}
|
|
64661
64860
|
return result2;
|
|
64662
64861
|
}
|
|
64663
|
-
function getApparentMappedTypeKeys(nameType,
|
|
64664
|
-
const modifiersType = getApparentType(getModifiersTypeFromMappedType(
|
|
64862
|
+
function getApparentMappedTypeKeys(nameType, mappedType) {
|
|
64863
|
+
const modifiersType = getApparentType(getModifiersTypeFromMappedType(mappedType));
|
|
64665
64864
|
const mappedKeys = [];
|
|
64666
64865
|
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(
|
|
64667
64866
|
modifiersType,
|
|
64668
64867
|
8576 /* StringOrNumberLiteralOrUnique */,
|
|
64669
64868
|
/*stringsOnly*/
|
|
64670
64869
|
false,
|
|
64671
|
-
(t) => void mappedKeys.push(instantiateType(nameType, appendTypeMapping(
|
|
64870
|
+
(t) => void mappedKeys.push(instantiateType(nameType, appendTypeMapping(mappedType.mapper, getTypeParameterFromMappedType(mappedType), t)))
|
|
64672
64871
|
);
|
|
64673
64872
|
return getUnionType(mappedKeys);
|
|
64674
64873
|
}
|
|
@@ -65033,7 +65232,15 @@ function createTypeChecker(host) {
|
|
|
65033
65232
|
if (isDeferredMappedIndex) {
|
|
65034
65233
|
const mappedType = source2.type;
|
|
65035
65234
|
const nameType = getNameTypeFromMappedType(mappedType);
|
|
65036
|
-
|
|
65235
|
+
let sourceMappedKeys;
|
|
65236
|
+
if (nameType && isMappedTypeWithKeyofConstraintDeclaration(mappedType)) {
|
|
65237
|
+
sourceMappedKeys = getApparentMappedTypeKeys(nameType, mappedType);
|
|
65238
|
+
if (sourceMappedKeys.flags & 131072 /* Never */) {
|
|
65239
|
+
sourceMappedKeys = stringNumberSymbolType;
|
|
65240
|
+
}
|
|
65241
|
+
} else {
|
|
65242
|
+
sourceMappedKeys = nameType || getConstraintTypeFromMappedType(mappedType);
|
|
65243
|
+
}
|
|
65037
65244
|
if (result2 = isRelatedTo(sourceMappedKeys, target2, 1 /* Source */, reportErrors2)) {
|
|
65038
65245
|
return result2;
|
|
65039
65246
|
}
|
|
@@ -68727,6 +68934,18 @@ function createTypeChecker(host) {
|
|
|
68727
68934
|
}
|
|
68728
68935
|
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
|
|
68729
68936
|
}
|
|
68937
|
+
function mapTypeToIntersection(type, mapper) {
|
|
68938
|
+
if (type.flags & 131072 /* Never */) {
|
|
68939
|
+
return type;
|
|
68940
|
+
}
|
|
68941
|
+
if (!(type.flags & 1048576 /* Union */)) {
|
|
68942
|
+
return mapper(type);
|
|
68943
|
+
}
|
|
68944
|
+
const origin = type.origin;
|
|
68945
|
+
const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
|
|
68946
|
+
const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
|
|
68947
|
+
return getIntersectionType(mappedTypes);
|
|
68948
|
+
}
|
|
68730
68949
|
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
|
|
68731
68950
|
return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
|
|
68732
68951
|
}
|
|
@@ -70309,11 +70528,11 @@ function createTypeChecker(host) {
|
|
|
70309
70528
|
));
|
|
70310
70529
|
return contextualType && !isGenericType(contextualType);
|
|
70311
70530
|
}
|
|
70312
|
-
function getNarrowableTypeForReference(type, reference, checkMode) {
|
|
70531
|
+
function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
|
|
70313
70532
|
if (isNoInferType(type)) {
|
|
70314
70533
|
type = type.baseType;
|
|
70315
70534
|
}
|
|
70316
|
-
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70535
|
+
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70317
70536
|
return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
|
|
70318
70537
|
}
|
|
70319
70538
|
function isExportOrExportExpression(location) {
|
|
@@ -70466,7 +70685,7 @@ function createTypeChecker(host) {
|
|
|
70466
70685
|
jsxFactorySym = resolveName(
|
|
70467
70686
|
jsxFactoryLocation,
|
|
70468
70687
|
jsxFactoryNamespace,
|
|
70469
|
-
compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70688
|
+
compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70470
70689
|
jsxFactoryRefErr,
|
|
70471
70690
|
/*isUse*/
|
|
70472
70691
|
true
|
|
@@ -70485,7 +70704,7 @@ function createTypeChecker(host) {
|
|
|
70485
70704
|
resolveName(
|
|
70486
70705
|
jsxFactoryLocation,
|
|
70487
70706
|
localJsxNamespace,
|
|
70488
|
-
compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70707
|
+
compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70489
70708
|
jsxFactoryRefErr,
|
|
70490
70709
|
/*isUse*/
|
|
70491
70710
|
true
|
|
@@ -71438,9 +71657,16 @@ function createTypeChecker(host) {
|
|
|
71438
71657
|
function getContextualTypeForReturnExpression(node, contextFlags) {
|
|
71439
71658
|
const func = getContainingFunction(node);
|
|
71440
71659
|
if (func) {
|
|
71660
|
+
const functionFlags = getFunctionFlags(func);
|
|
71661
|
+
const links = getNodeLinks(node);
|
|
71662
|
+
if (links.contextualReturnType) {
|
|
71663
|
+
if (functionFlags & 2 /* Async */) {
|
|
71664
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
71665
|
+
}
|
|
71666
|
+
return links.contextualReturnType;
|
|
71667
|
+
}
|
|
71441
71668
|
let contextualReturnType = getContextualReturnType(func, contextFlags);
|
|
71442
71669
|
if (contextualReturnType) {
|
|
71443
|
-
const functionFlags = getFunctionFlags(func);
|
|
71444
71670
|
if (functionFlags & 1 /* Generator */) {
|
|
71445
71671
|
const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
|
|
71446
71672
|
if (contextualReturnType.flags & 1048576 /* Union */) {
|
|
@@ -72138,6 +72364,13 @@ function createTypeChecker(host) {
|
|
|
72138
72364
|
if (index >= 0) {
|
|
72139
72365
|
return contextualTypes[index];
|
|
72140
72366
|
}
|
|
72367
|
+
const links = getNodeLinks(node);
|
|
72368
|
+
if (links.contextualReturnType) {
|
|
72369
|
+
if (node.flags & 65536 /* AwaitContext */) {
|
|
72370
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
72371
|
+
}
|
|
72372
|
+
return links.contextualReturnType;
|
|
72373
|
+
}
|
|
72141
72374
|
const { parent } = node;
|
|
72142
72375
|
switch (parent.kind) {
|
|
72143
72376
|
case 260 /* VariableDeclaration */:
|
|
@@ -74814,8 +75047,8 @@ function createTypeChecker(host) {
|
|
|
74814
75047
|
}
|
|
74815
75048
|
}
|
|
74816
75049
|
function getEffectiveCheckNode(argument) {
|
|
74817
|
-
|
|
74818
|
-
return
|
|
75050
|
+
const flags = isInJSFile(argument) ? 1 /* Parentheses */ | 32 /* Satisfies */ | -2147483648 /* ExcludeJSDocTypeAssertion */ : 1 /* Parentheses */ | 32 /* Satisfies */;
|
|
75051
|
+
return skipOuterExpressions(argument, flags);
|
|
74819
75052
|
}
|
|
74820
75053
|
function getSignatureApplicabilityError(node, args, signature, relation, checkMode, reportErrors2, containingMessageChain, inferenceContext) {
|
|
74821
75054
|
const errorOutputContainer = { errors: void 0, skipLogging: true };
|
|
@@ -75240,11 +75473,16 @@ function createTypeChecker(host) {
|
|
|
75240
75473
|
if (!result) {
|
|
75241
75474
|
result = chooseOverload(candidates, assignableRelation, isSingleNonGenericCandidate, signatureHelpTrailingComma);
|
|
75242
75475
|
}
|
|
75476
|
+
const links = getNodeLinks(node);
|
|
75477
|
+
if (links.resolvedSignature !== resolvingSignature && !candidatesOutArray) {
|
|
75478
|
+
Debug.assert(links.resolvedSignature);
|
|
75479
|
+
return links.resolvedSignature;
|
|
75480
|
+
}
|
|
75243
75481
|
if (result) {
|
|
75244
75482
|
return result;
|
|
75245
75483
|
}
|
|
75246
75484
|
result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
|
|
75247
|
-
|
|
75485
|
+
links.resolvedSignature = result;
|
|
75248
75486
|
if (reportErrors2) {
|
|
75249
75487
|
if (!headMessage && isInstanceof) {
|
|
75250
75488
|
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;
|
|
@@ -76009,7 +76247,7 @@ function createTypeChecker(host) {
|
|
|
76009
76247
|
const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ?? resolveName(
|
|
76010
76248
|
node,
|
|
76011
76249
|
jsxFragmentFactoryName,
|
|
76012
|
-
compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
76250
|
+
compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
76013
76251
|
/*nameNotFoundMessage*/
|
|
76014
76252
|
jsxFactoryRefErr,
|
|
76015
76253
|
/*isUse*/
|
|
@@ -76128,12 +76366,9 @@ function createTypeChecker(host) {
|
|
|
76128
76366
|
resolutionStart = resolutionTargets.length;
|
|
76129
76367
|
}
|
|
76130
76368
|
links.resolvedSignature = resolvingSignature;
|
|
76131
|
-
|
|
76369
|
+
const result = resolveSignature(node, candidatesOutArray, checkMode || 0 /* Normal */);
|
|
76132
76370
|
resolutionStart = saveResolutionStart;
|
|
76133
76371
|
if (result !== resolvingSignature) {
|
|
76134
|
-
if (links.resolvedSignature !== resolvingSignature) {
|
|
76135
|
-
result = links.resolvedSignature;
|
|
76136
|
-
}
|
|
76137
76372
|
links.resolvedSignature = flowLoopStart === flowLoopCount ? result : cached;
|
|
76138
76373
|
}
|
|
76139
76374
|
return result;
|
|
@@ -77661,7 +77896,7 @@ function createTypeChecker(host) {
|
|
|
77661
77896
|
});
|
|
77662
77897
|
}
|
|
77663
77898
|
function checkIfExpressionRefinesParameter(func, expr, param, initType) {
|
|
77664
|
-
const antecedent = expr.flowNode || expr.parent.kind === 253 /* ReturnStatement */ && expr.parent.flowNode || createFlowNode(
|
|
77899
|
+
const antecedent = canHaveFlowNode(expr) && expr.flowNode || expr.parent.kind === 253 /* ReturnStatement */ && expr.parent.flowNode || createFlowNode(
|
|
77665
77900
|
2 /* Start */,
|
|
77666
77901
|
/*node*/
|
|
77667
77902
|
void 0,
|
|
@@ -77809,19 +78044,7 @@ function createTypeChecker(host) {
|
|
|
77809
78044
|
const exprType = checkExpression(node.body);
|
|
77810
78045
|
const returnOrPromisedType = returnType && unwrapReturnType(returnType, functionFlags);
|
|
77811
78046
|
if (returnOrPromisedType) {
|
|
77812
|
-
|
|
77813
|
-
if ((functionFlags & 3 /* AsyncGenerator */) === 2 /* Async */) {
|
|
77814
|
-
const awaitedType = checkAwaitedType(
|
|
77815
|
-
exprType,
|
|
77816
|
-
/*withAlias*/
|
|
77817
|
-
false,
|
|
77818
|
-
effectiveCheckNode,
|
|
77819
|
-
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
77820
|
-
);
|
|
77821
|
-
checkTypeAssignableToAndOptionallyElaborate(awaitedType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
|
|
77822
|
-
} else {
|
|
77823
|
-
checkTypeAssignableToAndOptionallyElaborate(exprType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
|
|
77824
|
-
}
|
|
78047
|
+
checkReturnExpression(node, returnOrPromisedType, node.body, node.body, exprType);
|
|
77825
78048
|
}
|
|
77826
78049
|
}
|
|
77827
78050
|
}
|
|
@@ -77904,7 +78127,7 @@ function createTypeChecker(host) {
|
|
|
77904
78127
|
return false;
|
|
77905
78128
|
}
|
|
77906
78129
|
function checkReferenceExpression(expr, invalidReferenceMessage, invalidOptionalChainMessage) {
|
|
77907
|
-
const node = skipOuterExpressions(expr,
|
|
78130
|
+
const node = skipOuterExpressions(expr, 38 /* Assertions */ | 1 /* Parentheses */);
|
|
77908
78131
|
if (node.kind !== 80 /* Identifier */ && !isAccessExpression(node)) {
|
|
77909
78132
|
error(expr, invalidReferenceMessage);
|
|
77910
78133
|
return false;
|
|
@@ -78555,7 +78778,7 @@ function createTypeChecker(host) {
|
|
|
78555
78778
|
if (isBinaryExpression(right) && (right.operatorToken.kind === 57 /* BarBarToken */ || right.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
|
|
78556
78779
|
grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
|
|
78557
78780
|
}
|
|
78558
|
-
const leftTarget = skipOuterExpressions(left,
|
|
78781
|
+
const leftTarget = skipOuterExpressions(left, 63 /* All */);
|
|
78559
78782
|
const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
|
|
78560
78783
|
if (nullishSemantics !== 3 /* Sometimes */) {
|
|
78561
78784
|
if (node.parent.kind === 226 /* BinaryExpression */) {
|
|
@@ -78575,7 +78798,9 @@ function createTypeChecker(host) {
|
|
|
78575
78798
|
switch (node.kind) {
|
|
78576
78799
|
case 223 /* AwaitExpression */:
|
|
78577
78800
|
case 213 /* CallExpression */:
|
|
78801
|
+
case 215 /* TaggedTemplateExpression */:
|
|
78578
78802
|
case 212 /* ElementAccessExpression */:
|
|
78803
|
+
case 236 /* MetaProperty */:
|
|
78579
78804
|
case 214 /* NewExpression */:
|
|
78580
78805
|
case 211 /* PropertyAccessExpression */:
|
|
78581
78806
|
case 229 /* YieldExpression */:
|
|
@@ -78591,6 +78816,8 @@ function createTypeChecker(host) {
|
|
|
78591
78816
|
case 56 /* AmpersandAmpersandToken */:
|
|
78592
78817
|
case 77 /* AmpersandAmpersandEqualsToken */:
|
|
78593
78818
|
return 3 /* Sometimes */;
|
|
78819
|
+
case 28 /* CommaToken */:
|
|
78820
|
+
return getSyntacticNullishnessSemantics(node.right);
|
|
78594
78821
|
}
|
|
78595
78822
|
return 2 /* Never */;
|
|
78596
78823
|
case 227 /* ConditionalExpression */:
|
|
@@ -83043,7 +83270,6 @@ function createTypeChecker(host) {
|
|
|
83043
83270
|
}
|
|
83044
83271
|
const signature = getSignatureFromDeclaration(container);
|
|
83045
83272
|
const returnType = getReturnTypeOfSignature(signature);
|
|
83046
|
-
const functionFlags = getFunctionFlags(container);
|
|
83047
83273
|
if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
|
|
83048
83274
|
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
|
83049
83275
|
if (container.kind === 178 /* SetAccessor */) {
|
|
@@ -83051,26 +83277,249 @@ function createTypeChecker(host) {
|
|
|
83051
83277
|
error(node, Diagnostics.Setters_cannot_return_a_value);
|
|
83052
83278
|
}
|
|
83053
83279
|
} else if (container.kind === 176 /* Constructor */) {
|
|
83054
|
-
|
|
83280
|
+
const exprType2 = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
|
83281
|
+
if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType2, returnType, node, node.expression)) {
|
|
83055
83282
|
error(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
|
|
83056
83283
|
}
|
|
83057
83284
|
} else if (getReturnTypeFromAnnotation(container)) {
|
|
83058
|
-
const unwrappedReturnType = unwrapReturnType(returnType,
|
|
83059
|
-
|
|
83060
|
-
exprType,
|
|
83061
|
-
/*withAlias*/
|
|
83062
|
-
false,
|
|
83063
|
-
node,
|
|
83064
|
-
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83065
|
-
) : exprType;
|
|
83066
|
-
if (unwrappedReturnType) {
|
|
83067
|
-
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, node, node.expression);
|
|
83068
|
-
}
|
|
83285
|
+
const unwrappedReturnType = unwrapReturnType(returnType, getFunctionFlags(container)) ?? returnType;
|
|
83286
|
+
checkReturnExpression(container, unwrappedReturnType, node, node.expression, exprType);
|
|
83069
83287
|
}
|
|
83070
83288
|
} else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
|
|
83071
83289
|
error(node, Diagnostics.Not_all_code_paths_return_a_value);
|
|
83072
83290
|
}
|
|
83073
83291
|
}
|
|
83292
|
+
function checkReturnExpression(container, unwrappedReturnType, node, expr, exprType, inConditionalExpression = false) {
|
|
83293
|
+
const excludeJSDocTypeAssertions = isInJSFile(node);
|
|
83294
|
+
const functionFlags = getFunctionFlags(container);
|
|
83295
|
+
if (expr) {
|
|
83296
|
+
const unwrappedExpr = skipParentheses(expr, excludeJSDocTypeAssertions);
|
|
83297
|
+
if (isConditionalExpression(unwrappedExpr)) {
|
|
83298
|
+
checkReturnExpression(
|
|
83299
|
+
container,
|
|
83300
|
+
unwrappedReturnType,
|
|
83301
|
+
node,
|
|
83302
|
+
unwrappedExpr.whenTrue,
|
|
83303
|
+
checkExpression(unwrappedExpr.whenTrue),
|
|
83304
|
+
/*inConditionalExpression*/
|
|
83305
|
+
true
|
|
83306
|
+
);
|
|
83307
|
+
checkReturnExpression(
|
|
83308
|
+
container,
|
|
83309
|
+
unwrappedReturnType,
|
|
83310
|
+
node,
|
|
83311
|
+
unwrappedExpr.whenFalse,
|
|
83312
|
+
checkExpression(unwrappedExpr.whenFalse),
|
|
83313
|
+
/*inConditionalExpression*/
|
|
83314
|
+
true
|
|
83315
|
+
);
|
|
83316
|
+
return;
|
|
83317
|
+
}
|
|
83318
|
+
}
|
|
83319
|
+
const inReturnStatement = node.kind === 253 /* ReturnStatement */;
|
|
83320
|
+
const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83321
|
+
exprType,
|
|
83322
|
+
/*withAlias*/
|
|
83323
|
+
false,
|
|
83324
|
+
node,
|
|
83325
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83326
|
+
) : exprType;
|
|
83327
|
+
const effectiveExpr = expr && getEffectiveCheckNode(expr);
|
|
83328
|
+
const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
|
|
83329
|
+
if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
|
|
83330
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83331
|
+
return;
|
|
83332
|
+
}
|
|
83333
|
+
if (checkTypeAssignableTo(
|
|
83334
|
+
unwrappedExprType,
|
|
83335
|
+
unwrappedReturnType,
|
|
83336
|
+
/*errorNode*/
|
|
83337
|
+
void 0
|
|
83338
|
+
)) {
|
|
83339
|
+
return;
|
|
83340
|
+
}
|
|
83341
|
+
let narrowPosition = node;
|
|
83342
|
+
let narrowFlowNode = inReturnStatement && node.flowNode;
|
|
83343
|
+
if (expr && isConditionalExpression(expr.parent)) {
|
|
83344
|
+
narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
|
|
83345
|
+
narrowPosition = expr;
|
|
83346
|
+
}
|
|
83347
|
+
if (!narrowFlowNode) {
|
|
83348
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83349
|
+
return;
|
|
83350
|
+
}
|
|
83351
|
+
const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
|
|
83352
|
+
container,
|
|
83353
|
+
/*includeThisTypes*/
|
|
83354
|
+
false
|
|
83355
|
+
), getEffectiveTypeParameterDeclarations(container));
|
|
83356
|
+
const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
|
|
83357
|
+
if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
|
|
83358
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83359
|
+
return;
|
|
83360
|
+
}
|
|
83361
|
+
const narrowedTypeParameters = [];
|
|
83362
|
+
const narrowedTypes = [];
|
|
83363
|
+
for (const [typeParam, symbol, reference] of narrowableTypeParameters) {
|
|
83364
|
+
const narrowReference = factory.cloneNode(reference);
|
|
83365
|
+
narrowReference.id = void 0;
|
|
83366
|
+
getNodeLinks(narrowReference).resolvedSymbol = symbol;
|
|
83367
|
+
setParent(narrowReference, narrowPosition.parent);
|
|
83368
|
+
narrowReference.flowNode = narrowFlowNode;
|
|
83369
|
+
const initialType = getNarrowableTypeForReference(
|
|
83370
|
+
typeParam,
|
|
83371
|
+
narrowReference,
|
|
83372
|
+
/*checkMode*/
|
|
83373
|
+
void 0,
|
|
83374
|
+
/*forReturnTypeNarrowing*/
|
|
83375
|
+
true
|
|
83376
|
+
);
|
|
83377
|
+
if (initialType === typeParam) {
|
|
83378
|
+
continue;
|
|
83379
|
+
}
|
|
83380
|
+
const flowType = getFlowTypeOfReference(narrowReference, initialType);
|
|
83381
|
+
const exprType2 = getTypeFromFlowType(flowType);
|
|
83382
|
+
if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
|
|
83383
|
+
continue;
|
|
83384
|
+
}
|
|
83385
|
+
const narrowedType = getSubstitutionType(
|
|
83386
|
+
typeParam,
|
|
83387
|
+
exprType2,
|
|
83388
|
+
/*isNarrowed*/
|
|
83389
|
+
true
|
|
83390
|
+
);
|
|
83391
|
+
narrowedTypeParameters.push(typeParam);
|
|
83392
|
+
narrowedTypes.push(narrowedType);
|
|
83393
|
+
}
|
|
83394
|
+
const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
|
|
83395
|
+
const narrowedReturnType = instantiateType(
|
|
83396
|
+
unwrappedReturnType,
|
|
83397
|
+
narrowMapper
|
|
83398
|
+
);
|
|
83399
|
+
if (expr) {
|
|
83400
|
+
const links = getNodeLinks(expr);
|
|
83401
|
+
if (!links.contextualReturnType) {
|
|
83402
|
+
links.contextualReturnType = narrowedReturnType;
|
|
83403
|
+
}
|
|
83404
|
+
}
|
|
83405
|
+
const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
|
|
83406
|
+
const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83407
|
+
narrowedExprType,
|
|
83408
|
+
/*withAlias*/
|
|
83409
|
+
false,
|
|
83410
|
+
node,
|
|
83411
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83412
|
+
) : narrowedExprType;
|
|
83413
|
+
checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
|
|
83414
|
+
}
|
|
83415
|
+
function getNarrowableTypeParameters(candidates) {
|
|
83416
|
+
const narrowableParams = [];
|
|
83417
|
+
for (const typeParam of candidates) {
|
|
83418
|
+
const constraint = getConstraintOfTypeParameter(typeParam);
|
|
83419
|
+
if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
|
|
83420
|
+
if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
|
|
83421
|
+
const declaration = typeParam.symbol.declarations[0];
|
|
83422
|
+
const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
|
|
83423
|
+
if (!isFunctionLike(container)) continue;
|
|
83424
|
+
let reference;
|
|
83425
|
+
let hasInvalidReference = false;
|
|
83426
|
+
for (const paramDecl of container.parameters) {
|
|
83427
|
+
const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
|
|
83428
|
+
if (!typeNode) continue;
|
|
83429
|
+
if (isTypeParameterReferenced(typeParam, typeNode)) {
|
|
83430
|
+
let candidateReference;
|
|
83431
|
+
if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
|
|
83432
|
+
if (reference) {
|
|
83433
|
+
hasInvalidReference = true;
|
|
83434
|
+
break;
|
|
83435
|
+
}
|
|
83436
|
+
reference = candidateReference;
|
|
83437
|
+
} else {
|
|
83438
|
+
hasInvalidReference = true;
|
|
83439
|
+
break;
|
|
83440
|
+
}
|
|
83441
|
+
}
|
|
83442
|
+
}
|
|
83443
|
+
if (!hasInvalidReference && reference) {
|
|
83444
|
+
const symbol = getResolvedSymbol(reference);
|
|
83445
|
+
if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
|
|
83446
|
+
}
|
|
83447
|
+
}
|
|
83448
|
+
}
|
|
83449
|
+
return narrowableParams;
|
|
83450
|
+
function getValidParameterReference(paramDecl, constraint) {
|
|
83451
|
+
if (!isIdentifier(paramDecl.name)) return;
|
|
83452
|
+
const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
|
|
83453
|
+
if (isOptional && !containsUndefinedType(constraint)) return;
|
|
83454
|
+
return paramDecl.name;
|
|
83455
|
+
}
|
|
83456
|
+
function isReferenceToTypeParameter(typeParam, node) {
|
|
83457
|
+
return getTypeFromTypeReference(node) === typeParam;
|
|
83458
|
+
}
|
|
83459
|
+
function isTypeParameterReferenced(typeParam, node) {
|
|
83460
|
+
return isReferenced(node);
|
|
83461
|
+
function isReferenced(node2) {
|
|
83462
|
+
if (isTypeReferenceNode(node2)) {
|
|
83463
|
+
return isReferenceToTypeParameter(typeParam, node2);
|
|
83464
|
+
}
|
|
83465
|
+
if (isTypeQueryNode(node2)) {
|
|
83466
|
+
return isTypeParameterPossiblyReferenced(typeParam, node2);
|
|
83467
|
+
}
|
|
83468
|
+
return !!forEachChild(node2, isReferenced);
|
|
83469
|
+
}
|
|
83470
|
+
}
|
|
83471
|
+
}
|
|
83472
|
+
function isNarrowableReturnType(returnType) {
|
|
83473
|
+
return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
|
|
83474
|
+
}
|
|
83475
|
+
function isNarrowableConditionalType(type, mapper) {
|
|
83476
|
+
const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
|
|
83477
|
+
const mapped = getMappedType(t, mapper);
|
|
83478
|
+
if (isNarrowingSubstitutionType(mapped)) {
|
|
83479
|
+
return mapped.baseType;
|
|
83480
|
+
}
|
|
83481
|
+
return mapped;
|
|
83482
|
+
});
|
|
83483
|
+
const id = `${type.id}:${getTypeListId(typeArguments)}`;
|
|
83484
|
+
let result = narrowableReturnTypeCache.get(id);
|
|
83485
|
+
if (result === void 0) {
|
|
83486
|
+
const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
|
|
83487
|
+
const instantiatedType = instantiateType(type, nonNarrowingMapper);
|
|
83488
|
+
result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
|
|
83489
|
+
narrowableReturnTypeCache.set(id, result);
|
|
83490
|
+
}
|
|
83491
|
+
return result;
|
|
83492
|
+
}
|
|
83493
|
+
function isNarrowableConditionalTypeWorker(type) {
|
|
83494
|
+
if (!type.root.isDistributive) {
|
|
83495
|
+
return false;
|
|
83496
|
+
}
|
|
83497
|
+
if (type.root.inferTypeParameters) {
|
|
83498
|
+
return false;
|
|
83499
|
+
}
|
|
83500
|
+
if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
|
|
83501
|
+
return false;
|
|
83502
|
+
}
|
|
83503
|
+
const constraintType = getConstraintOfTypeParameter(type.checkType);
|
|
83504
|
+
if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
|
|
83505
|
+
return false;
|
|
83506
|
+
}
|
|
83507
|
+
if (!everyType(type.extendsType, (extendsType) => some(
|
|
83508
|
+
constraintType.types,
|
|
83509
|
+
(constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
|
|
83510
|
+
))) {
|
|
83511
|
+
return false;
|
|
83512
|
+
}
|
|
83513
|
+
const trueType2 = getTrueTypeFromConditionalType(type);
|
|
83514
|
+
const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
|
|
83515
|
+
if (!isValidTrueType) return false;
|
|
83516
|
+
const falseType2 = getFalseTypeFromConditionalType(type);
|
|
83517
|
+
const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
|
|
83518
|
+
return isValidFalseType;
|
|
83519
|
+
}
|
|
83520
|
+
function isConditionalType(type) {
|
|
83521
|
+
return !!(type.flags & 16777216 /* Conditional */);
|
|
83522
|
+
}
|
|
83074
83523
|
function checkWithStatement(node) {
|
|
83075
83524
|
if (!checkGrammarStatementInAmbientContext(node)) {
|
|
83076
83525
|
if (node.flags & 65536 /* AwaitContext */) {
|
|
@@ -93044,7 +93493,7 @@ function transformTypeScript(context) {
|
|
|
93044
93493
|
return updated;
|
|
93045
93494
|
}
|
|
93046
93495
|
function visitParenthesizedExpression(node) {
|
|
93047
|
-
const innerExpression = skipOuterExpressions(node.expression, ~(
|
|
93496
|
+
const innerExpression = skipOuterExpressions(node.expression, ~(38 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
|
|
93048
93497
|
if (isAssertionExpression(innerExpression) || isSatisfiesExpression(innerExpression)) {
|
|
93049
93498
|
const expression = visitNode(node.expression, visitor, isExpression);
|
|
93050
93499
|
Debug.assert(expression);
|
|
@@ -131999,18 +132448,21 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131999
132448
|
return failed;
|
|
132000
132449
|
}
|
|
132001
132450
|
function typeFromFunctionLikeExpression(fnNode, context) {
|
|
132002
|
-
const
|
|
132003
|
-
context.noInferenceFallback = true;
|
|
132004
|
-
createReturnFromSignature(
|
|
132451
|
+
const returnType = createReturnFromSignature(
|
|
132005
132452
|
fnNode,
|
|
132006
132453
|
/*symbol*/
|
|
132007
132454
|
void 0,
|
|
132008
132455
|
context
|
|
132009
132456
|
);
|
|
132010
|
-
reuseTypeParameters(fnNode.typeParameters, context);
|
|
132011
|
-
fnNode.parameters.map((p) => ensureParameter(p, context));
|
|
132012
|
-
|
|
132013
|
-
|
|
132457
|
+
const typeParameters = reuseTypeParameters(fnNode.typeParameters, context);
|
|
132458
|
+
const parameters = fnNode.parameters.map((p) => ensureParameter(p, context));
|
|
132459
|
+
return syntacticResult(
|
|
132460
|
+
factory.createFunctionTypeNode(
|
|
132461
|
+
typeParameters,
|
|
132462
|
+
parameters,
|
|
132463
|
+
returnType
|
|
132464
|
+
)
|
|
132465
|
+
);
|
|
132014
132466
|
}
|
|
132015
132467
|
function canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext) {
|
|
132016
132468
|
if (!isConstContext) {
|