@typescript-deploys/pr-build 5.7.0-pr-57718-9 → 5.8.0-pr-52972-10
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 +585 -130
- 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.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 +788 -219
- 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.20241127`;
|
|
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(
|
|
@@ -57183,12 +57342,20 @@ function createTypeChecker(host) {
|
|
|
57183
57342
|
const indexInfos = indexInfo ? [createIndexInfo(stringType, inferReverseMappedType(indexInfo.type, type.mappedType, type.constraintType) || unknownType, readonlyMask && indexInfo.isReadonly)] : emptyArray;
|
|
57184
57343
|
const members = createSymbolTable();
|
|
57185
57344
|
const limitedConstraint = getLimitedConstraint(type);
|
|
57345
|
+
const nameType = getNameTypeFromMappedType(type.mappedType);
|
|
57186
57346
|
for (const prop of getPropertiesOfType(type.source)) {
|
|
57187
|
-
if (limitedConstraint) {
|
|
57347
|
+
if (limitedConstraint || nameType) {
|
|
57188
57348
|
const propertyNameType = getLiteralTypeFromProperty(prop, 8576 /* StringOrNumberLiteralOrUnique */);
|
|
57189
|
-
if (!isTypeAssignableTo(propertyNameType, limitedConstraint)) {
|
|
57349
|
+
if (limitedConstraint && !isTypeAssignableTo(propertyNameType, limitedConstraint)) {
|
|
57190
57350
|
continue;
|
|
57191
57351
|
}
|
|
57352
|
+
if (nameType) {
|
|
57353
|
+
const nameMapper = appendTypeMapping(type.mappedType.mapper, getTypeParameterFromMappedType(type.mappedType), propertyNameType);
|
|
57354
|
+
const instantiatedNameType = instantiateType(nameType, nameMapper);
|
|
57355
|
+
if (instantiatedNameType.flags & 131072 /* Never */) {
|
|
57356
|
+
continue;
|
|
57357
|
+
}
|
|
57358
|
+
}
|
|
57192
57359
|
}
|
|
57193
57360
|
const checkFlags = 8192 /* ReverseMapped */ | (readonlyMask && isReadonlySymbol(prop) ? 8 /* Readonly */ : 0);
|
|
57194
57361
|
const inferredProp = createSymbol(4 /* Property */ | prop.flags & optionalMask, prop.escapedName, checkFlags);
|
|
@@ -59184,11 +59351,14 @@ function createTypeChecker(host) {
|
|
|
59184
59351
|
function isNoInferType(type) {
|
|
59185
59352
|
return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
|
|
59186
59353
|
}
|
|
59187
|
-
function
|
|
59188
|
-
return
|
|
59354
|
+
function isNarrowingSubstitutionType(type) {
|
|
59355
|
+
return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
|
|
59189
59356
|
}
|
|
59190
|
-
function
|
|
59191
|
-
|
|
59357
|
+
function getSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59358
|
+
return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
|
|
59359
|
+
}
|
|
59360
|
+
function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
|
|
59361
|
+
const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
|
|
59192
59362
|
const cached = substitutionTypes.get(id);
|
|
59193
59363
|
if (cached) {
|
|
59194
59364
|
return cached;
|
|
@@ -59196,6 +59366,9 @@ function createTypeChecker(host) {
|
|
|
59196
59366
|
const result = createType(33554432 /* Substitution */);
|
|
59197
59367
|
result.baseType = baseType;
|
|
59198
59368
|
result.constraint = constraint;
|
|
59369
|
+
if (isNarrowed) {
|
|
59370
|
+
result.objectFlags |= 16777216 /* IsNarrowingType */;
|
|
59371
|
+
}
|
|
59199
59372
|
substitutionTypes.set(id, result);
|
|
59200
59373
|
return result;
|
|
59201
59374
|
}
|
|
@@ -61398,7 +61571,7 @@ function createTypeChecker(host) {
|
|
|
61398
61571
|
function isDeferredType(type, checkTuples) {
|
|
61399
61572
|
return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
|
|
61400
61573
|
}
|
|
61401
|
-
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
|
|
61574
|
+
function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
|
|
61402
61575
|
let result;
|
|
61403
61576
|
let extraTypes;
|
|
61404
61577
|
let tailCount = 0;
|
|
@@ -61415,10 +61588,11 @@ function createTypeChecker(host) {
|
|
|
61415
61588
|
if (checkType === wildcardType || extendsType === wildcardType) {
|
|
61416
61589
|
return wildcardType;
|
|
61417
61590
|
}
|
|
61591
|
+
const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
|
|
61418
61592
|
const checkTypeNode = skipTypeParentheses(root.node.checkType);
|
|
61419
61593
|
const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
|
|
61420
61594
|
const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
|
|
61421
|
-
const checkTypeDeferred = isDeferredType(
|
|
61595
|
+
const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
|
|
61422
61596
|
let combinedMapper;
|
|
61423
61597
|
if (root.inferTypeParameters) {
|
|
61424
61598
|
const context = createInferenceContext(
|
|
@@ -61437,8 +61611,8 @@ function createTypeChecker(host) {
|
|
|
61437
61611
|
}
|
|
61438
61612
|
const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
|
|
61439
61613
|
if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
|
|
61440
|
-
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (
|
|
61441
|
-
if (
|
|
61614
|
+
if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
|
|
61615
|
+
if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
|
|
61442
61616
|
(extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
|
|
61443
61617
|
}
|
|
61444
61618
|
const falseType2 = getTypeFromTypeNode(root.node.falseType);
|
|
@@ -61455,7 +61629,7 @@ function createTypeChecker(host) {
|
|
|
61455
61629
|
result = instantiateType(falseType2, mapper);
|
|
61456
61630
|
break;
|
|
61457
61631
|
}
|
|
61458
|
-
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(
|
|
61632
|
+
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
|
|
61459
61633
|
const trueType2 = getTypeFromTypeNode(root.node.trueType);
|
|
61460
61634
|
const trueMapper = combinedMapper || mapper;
|
|
61461
61635
|
if (canTailRecurse(trueType2, trueMapper)) {
|
|
@@ -62421,8 +62595,39 @@ function createTypeChecker(host) {
|
|
|
62421
62595
|
if (!result) {
|
|
62422
62596
|
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
|
|
62423
62597
|
const checkType = root.checkType;
|
|
62424
|
-
|
|
62425
|
-
|
|
62598
|
+
let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
|
|
62599
|
+
let narrowingBaseType;
|
|
62600
|
+
const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
|
|
62601
|
+
if (forNarrowing) {
|
|
62602
|
+
narrowingBaseType = distributionType.baseType;
|
|
62603
|
+
distributionType = getReducedType(distributionType.constraint);
|
|
62604
|
+
}
|
|
62605
|
+
if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
|
|
62606
|
+
if (narrowingBaseType) {
|
|
62607
|
+
result = mapTypeToIntersection(
|
|
62608
|
+
distributionType,
|
|
62609
|
+
(t) => getConditionalType(
|
|
62610
|
+
root,
|
|
62611
|
+
prependTypeMapping(checkType, getSubstitutionType(
|
|
62612
|
+
narrowingBaseType,
|
|
62613
|
+
t,
|
|
62614
|
+
/*isNarrowed*/
|
|
62615
|
+
true
|
|
62616
|
+
), newMapper),
|
|
62617
|
+
forConstraint,
|
|
62618
|
+
/*aliasSymbol*/
|
|
62619
|
+
void 0,
|
|
62620
|
+
/*aliasTypeArguments*/
|
|
62621
|
+
void 0,
|
|
62622
|
+
forNarrowing
|
|
62623
|
+
)
|
|
62624
|
+
);
|
|
62625
|
+
} else {
|
|
62626
|
+
result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
|
|
62627
|
+
}
|
|
62628
|
+
} else {
|
|
62629
|
+
result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
|
|
62630
|
+
}
|
|
62426
62631
|
root.instantiations.set(id, result);
|
|
62427
62632
|
}
|
|
62428
62633
|
return result;
|
|
@@ -63565,10 +63770,12 @@ function createTypeChecker(host) {
|
|
|
63565
63770
|
function shouldNormalizeIntersection(type) {
|
|
63566
63771
|
let hasInstantiable = false;
|
|
63567
63772
|
let hasNullableOrEmpty = false;
|
|
63773
|
+
let hasSubstitution = false;
|
|
63568
63774
|
for (const t of type.types) {
|
|
63569
63775
|
hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
|
|
63570
63776
|
hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
|
|
63571
|
-
|
|
63777
|
+
hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
|
|
63778
|
+
if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
|
|
63572
63779
|
}
|
|
63573
63780
|
return false;
|
|
63574
63781
|
}
|
|
@@ -67776,10 +67983,13 @@ function createTypeChecker(host) {
|
|
|
67776
67983
|
if (isGenericMappedType(source) && isGenericMappedType(target)) {
|
|
67777
67984
|
inferFromGenericMappedTypes(source, target);
|
|
67778
67985
|
}
|
|
67779
|
-
if (getObjectFlags(target) & 32 /* Mapped */
|
|
67780
|
-
const
|
|
67781
|
-
if (
|
|
67782
|
-
|
|
67986
|
+
if (getObjectFlags(target) & 32 /* Mapped */) {
|
|
67987
|
+
const mappedType = target;
|
|
67988
|
+
if (getMappedTypeNameTypeKind(mappedType) !== 2 /* Remapping */) {
|
|
67989
|
+
const constraintType = getConstraintTypeFromMappedType(mappedType);
|
|
67990
|
+
if (inferToMappedType(source, mappedType, constraintType)) {
|
|
67991
|
+
return;
|
|
67992
|
+
}
|
|
67783
67993
|
}
|
|
67784
67994
|
}
|
|
67785
67995
|
if (!typesDefinitelyUnrelated(source, target)) {
|
|
@@ -68727,6 +68937,18 @@ function createTypeChecker(host) {
|
|
|
68727
68937
|
}
|
|
68728
68938
|
return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
|
|
68729
68939
|
}
|
|
68940
|
+
function mapTypeToIntersection(type, mapper) {
|
|
68941
|
+
if (type.flags & 131072 /* Never */) {
|
|
68942
|
+
return type;
|
|
68943
|
+
}
|
|
68944
|
+
if (!(type.flags & 1048576 /* Union */)) {
|
|
68945
|
+
return mapper(type);
|
|
68946
|
+
}
|
|
68947
|
+
const origin = type.origin;
|
|
68948
|
+
const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
|
|
68949
|
+
const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
|
|
68950
|
+
return getIntersectionType(mappedTypes);
|
|
68951
|
+
}
|
|
68730
68952
|
function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
|
|
68731
68953
|
return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
|
|
68732
68954
|
}
|
|
@@ -70309,11 +70531,11 @@ function createTypeChecker(host) {
|
|
|
70309
70531
|
));
|
|
70310
70532
|
return contextualType && !isGenericType(contextualType);
|
|
70311
70533
|
}
|
|
70312
|
-
function getNarrowableTypeForReference(type, reference, checkMode) {
|
|
70534
|
+
function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
|
|
70313
70535
|
if (isNoInferType(type)) {
|
|
70314
70536
|
type = type.baseType;
|
|
70315
70537
|
}
|
|
70316
|
-
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70538
|
+
const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
|
|
70317
70539
|
return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
|
|
70318
70540
|
}
|
|
70319
70541
|
function isExportOrExportExpression(location) {
|
|
@@ -70466,7 +70688,7 @@ function createTypeChecker(host) {
|
|
|
70466
70688
|
jsxFactorySym = resolveName(
|
|
70467
70689
|
jsxFactoryLocation,
|
|
70468
70690
|
jsxFactoryNamespace,
|
|
70469
|
-
compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70691
|
+
compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70470
70692
|
jsxFactoryRefErr,
|
|
70471
70693
|
/*isUse*/
|
|
70472
70694
|
true
|
|
@@ -70485,7 +70707,7 @@ function createTypeChecker(host) {
|
|
|
70485
70707
|
resolveName(
|
|
70486
70708
|
jsxFactoryLocation,
|
|
70487
70709
|
localJsxNamespace,
|
|
70488
|
-
compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70710
|
+
compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
70489
70711
|
jsxFactoryRefErr,
|
|
70490
70712
|
/*isUse*/
|
|
70491
70713
|
true
|
|
@@ -71438,9 +71660,16 @@ function createTypeChecker(host) {
|
|
|
71438
71660
|
function getContextualTypeForReturnExpression(node, contextFlags) {
|
|
71439
71661
|
const func = getContainingFunction(node);
|
|
71440
71662
|
if (func) {
|
|
71663
|
+
const functionFlags = getFunctionFlags(func);
|
|
71664
|
+
const links = getNodeLinks(node);
|
|
71665
|
+
if (links.contextualReturnType) {
|
|
71666
|
+
if (functionFlags & 2 /* Async */) {
|
|
71667
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
71668
|
+
}
|
|
71669
|
+
return links.contextualReturnType;
|
|
71670
|
+
}
|
|
71441
71671
|
let contextualReturnType = getContextualReturnType(func, contextFlags);
|
|
71442
71672
|
if (contextualReturnType) {
|
|
71443
|
-
const functionFlags = getFunctionFlags(func);
|
|
71444
71673
|
if (functionFlags & 1 /* Generator */) {
|
|
71445
71674
|
const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
|
|
71446
71675
|
if (contextualReturnType.flags & 1048576 /* Union */) {
|
|
@@ -72138,6 +72367,13 @@ function createTypeChecker(host) {
|
|
|
72138
72367
|
if (index >= 0) {
|
|
72139
72368
|
return contextualTypes[index];
|
|
72140
72369
|
}
|
|
72370
|
+
const links = getNodeLinks(node);
|
|
72371
|
+
if (links.contextualReturnType) {
|
|
72372
|
+
if (node.flags & 65536 /* AwaitContext */) {
|
|
72373
|
+
return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
|
|
72374
|
+
}
|
|
72375
|
+
return links.contextualReturnType;
|
|
72376
|
+
}
|
|
72141
72377
|
const { parent } = node;
|
|
72142
72378
|
switch (parent.kind) {
|
|
72143
72379
|
case 260 /* VariableDeclaration */:
|
|
@@ -74814,8 +75050,8 @@ function createTypeChecker(host) {
|
|
|
74814
75050
|
}
|
|
74815
75051
|
}
|
|
74816
75052
|
function getEffectiveCheckNode(argument) {
|
|
74817
|
-
|
|
74818
|
-
return
|
|
75053
|
+
const flags = isInJSFile(argument) ? 1 /* Parentheses */ | 32 /* Satisfies */ | -2147483648 /* ExcludeJSDocTypeAssertion */ : 1 /* Parentheses */ | 32 /* Satisfies */;
|
|
75054
|
+
return skipOuterExpressions(argument, flags);
|
|
74819
75055
|
}
|
|
74820
75056
|
function getSignatureApplicabilityError(node, args, signature, relation, checkMode, reportErrors2, containingMessageChain, inferenceContext) {
|
|
74821
75057
|
const errorOutputContainer = { errors: void 0, skipLogging: true };
|
|
@@ -75240,11 +75476,16 @@ function createTypeChecker(host) {
|
|
|
75240
75476
|
if (!result) {
|
|
75241
75477
|
result = chooseOverload(candidates, assignableRelation, isSingleNonGenericCandidate, signatureHelpTrailingComma);
|
|
75242
75478
|
}
|
|
75479
|
+
const links = getNodeLinks(node);
|
|
75480
|
+
if (links.resolvedSignature !== resolvingSignature && !candidatesOutArray) {
|
|
75481
|
+
Debug.assert(links.resolvedSignature);
|
|
75482
|
+
return links.resolvedSignature;
|
|
75483
|
+
}
|
|
75243
75484
|
if (result) {
|
|
75244
75485
|
return result;
|
|
75245
75486
|
}
|
|
75246
75487
|
result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
|
|
75247
|
-
|
|
75488
|
+
links.resolvedSignature = result;
|
|
75248
75489
|
if (reportErrors2) {
|
|
75249
75490
|
if (!headMessage && isInstanceof) {
|
|
75250
75491
|
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 +76250,7 @@ function createTypeChecker(host) {
|
|
|
76009
76250
|
const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ?? resolveName(
|
|
76010
76251
|
node,
|
|
76011
76252
|
jsxFragmentFactoryName,
|
|
76012
|
-
compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
76253
|
+
compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
|
|
76013
76254
|
/*nameNotFoundMessage*/
|
|
76014
76255
|
jsxFactoryRefErr,
|
|
76015
76256
|
/*isUse*/
|
|
@@ -76128,12 +76369,9 @@ function createTypeChecker(host) {
|
|
|
76128
76369
|
resolutionStart = resolutionTargets.length;
|
|
76129
76370
|
}
|
|
76130
76371
|
links.resolvedSignature = resolvingSignature;
|
|
76131
|
-
|
|
76372
|
+
const result = resolveSignature(node, candidatesOutArray, checkMode || 0 /* Normal */);
|
|
76132
76373
|
resolutionStart = saveResolutionStart;
|
|
76133
76374
|
if (result !== resolvingSignature) {
|
|
76134
|
-
if (links.resolvedSignature !== resolvingSignature) {
|
|
76135
|
-
result = links.resolvedSignature;
|
|
76136
|
-
}
|
|
76137
76375
|
links.resolvedSignature = flowLoopStart === flowLoopCount ? result : cached;
|
|
76138
76376
|
}
|
|
76139
76377
|
return result;
|
|
@@ -77661,7 +77899,7 @@ function createTypeChecker(host) {
|
|
|
77661
77899
|
});
|
|
77662
77900
|
}
|
|
77663
77901
|
function checkIfExpressionRefinesParameter(func, expr, param, initType) {
|
|
77664
|
-
const antecedent = expr.flowNode || expr.parent.kind === 253 /* ReturnStatement */ && expr.parent.flowNode || createFlowNode(
|
|
77902
|
+
const antecedent = canHaveFlowNode(expr) && expr.flowNode || expr.parent.kind === 253 /* ReturnStatement */ && expr.parent.flowNode || createFlowNode(
|
|
77665
77903
|
2 /* Start */,
|
|
77666
77904
|
/*node*/
|
|
77667
77905
|
void 0,
|
|
@@ -77809,19 +78047,7 @@ function createTypeChecker(host) {
|
|
|
77809
78047
|
const exprType = checkExpression(node.body);
|
|
77810
78048
|
const returnOrPromisedType = returnType && unwrapReturnType(returnType, functionFlags);
|
|
77811
78049
|
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
|
-
}
|
|
78050
|
+
checkReturnExpression(node, returnOrPromisedType, node.body, node.body, exprType);
|
|
77825
78051
|
}
|
|
77826
78052
|
}
|
|
77827
78053
|
}
|
|
@@ -77904,7 +78130,7 @@ function createTypeChecker(host) {
|
|
|
77904
78130
|
return false;
|
|
77905
78131
|
}
|
|
77906
78132
|
function checkReferenceExpression(expr, invalidReferenceMessage, invalidOptionalChainMessage) {
|
|
77907
|
-
const node = skipOuterExpressions(expr,
|
|
78133
|
+
const node = skipOuterExpressions(expr, 38 /* Assertions */ | 1 /* Parentheses */);
|
|
77908
78134
|
if (node.kind !== 80 /* Identifier */ && !isAccessExpression(node)) {
|
|
77909
78135
|
error(expr, invalidReferenceMessage);
|
|
77910
78136
|
return false;
|
|
@@ -78555,7 +78781,7 @@ function createTypeChecker(host) {
|
|
|
78555
78781
|
if (isBinaryExpression(right) && (right.operatorToken.kind === 57 /* BarBarToken */ || right.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
|
|
78556
78782
|
grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
|
|
78557
78783
|
}
|
|
78558
|
-
const leftTarget = skipOuterExpressions(left,
|
|
78784
|
+
const leftTarget = skipOuterExpressions(left, 63 /* All */);
|
|
78559
78785
|
const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
|
|
78560
78786
|
if (nullishSemantics !== 3 /* Sometimes */) {
|
|
78561
78787
|
if (node.parent.kind === 226 /* BinaryExpression */) {
|
|
@@ -78575,7 +78801,9 @@ function createTypeChecker(host) {
|
|
|
78575
78801
|
switch (node.kind) {
|
|
78576
78802
|
case 223 /* AwaitExpression */:
|
|
78577
78803
|
case 213 /* CallExpression */:
|
|
78804
|
+
case 215 /* TaggedTemplateExpression */:
|
|
78578
78805
|
case 212 /* ElementAccessExpression */:
|
|
78806
|
+
case 236 /* MetaProperty */:
|
|
78579
78807
|
case 214 /* NewExpression */:
|
|
78580
78808
|
case 211 /* PropertyAccessExpression */:
|
|
78581
78809
|
case 229 /* YieldExpression */:
|
|
@@ -78591,6 +78819,8 @@ function createTypeChecker(host) {
|
|
|
78591
78819
|
case 56 /* AmpersandAmpersandToken */:
|
|
78592
78820
|
case 77 /* AmpersandAmpersandEqualsToken */:
|
|
78593
78821
|
return 3 /* Sometimes */;
|
|
78822
|
+
case 28 /* CommaToken */:
|
|
78823
|
+
return getSyntacticNullishnessSemantics(node.right);
|
|
78594
78824
|
}
|
|
78595
78825
|
return 2 /* Never */;
|
|
78596
78826
|
case 227 /* ConditionalExpression */:
|
|
@@ -83043,7 +83273,6 @@ function createTypeChecker(host) {
|
|
|
83043
83273
|
}
|
|
83044
83274
|
const signature = getSignatureFromDeclaration(container);
|
|
83045
83275
|
const returnType = getReturnTypeOfSignature(signature);
|
|
83046
|
-
const functionFlags = getFunctionFlags(container);
|
|
83047
83276
|
if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
|
|
83048
83277
|
const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
|
83049
83278
|
if (container.kind === 178 /* SetAccessor */) {
|
|
@@ -83051,26 +83280,249 @@ function createTypeChecker(host) {
|
|
|
83051
83280
|
error(node, Diagnostics.Setters_cannot_return_a_value);
|
|
83052
83281
|
}
|
|
83053
83282
|
} else if (container.kind === 176 /* Constructor */) {
|
|
83054
|
-
|
|
83283
|
+
const exprType2 = node.expression ? checkExpressionCached(node.expression) : undefinedType;
|
|
83284
|
+
if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType2, returnType, node, node.expression)) {
|
|
83055
83285
|
error(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
|
|
83056
83286
|
}
|
|
83057
83287
|
} 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
|
-
}
|
|
83288
|
+
const unwrappedReturnType = unwrapReturnType(returnType, getFunctionFlags(container)) ?? returnType;
|
|
83289
|
+
checkReturnExpression(container, unwrappedReturnType, node, node.expression, exprType);
|
|
83069
83290
|
}
|
|
83070
83291
|
} else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
|
|
83071
83292
|
error(node, Diagnostics.Not_all_code_paths_return_a_value);
|
|
83072
83293
|
}
|
|
83073
83294
|
}
|
|
83295
|
+
function checkReturnExpression(container, unwrappedReturnType, node, expr, exprType, inConditionalExpression = false) {
|
|
83296
|
+
const excludeJSDocTypeAssertions = isInJSFile(node);
|
|
83297
|
+
const functionFlags = getFunctionFlags(container);
|
|
83298
|
+
if (expr) {
|
|
83299
|
+
const unwrappedExpr = skipParentheses(expr, excludeJSDocTypeAssertions);
|
|
83300
|
+
if (isConditionalExpression(unwrappedExpr)) {
|
|
83301
|
+
checkReturnExpression(
|
|
83302
|
+
container,
|
|
83303
|
+
unwrappedReturnType,
|
|
83304
|
+
node,
|
|
83305
|
+
unwrappedExpr.whenTrue,
|
|
83306
|
+
checkExpression(unwrappedExpr.whenTrue),
|
|
83307
|
+
/*inConditionalExpression*/
|
|
83308
|
+
true
|
|
83309
|
+
);
|
|
83310
|
+
checkReturnExpression(
|
|
83311
|
+
container,
|
|
83312
|
+
unwrappedReturnType,
|
|
83313
|
+
node,
|
|
83314
|
+
unwrappedExpr.whenFalse,
|
|
83315
|
+
checkExpression(unwrappedExpr.whenFalse),
|
|
83316
|
+
/*inConditionalExpression*/
|
|
83317
|
+
true
|
|
83318
|
+
);
|
|
83319
|
+
return;
|
|
83320
|
+
}
|
|
83321
|
+
}
|
|
83322
|
+
const inReturnStatement = node.kind === 253 /* ReturnStatement */;
|
|
83323
|
+
const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83324
|
+
exprType,
|
|
83325
|
+
/*withAlias*/
|
|
83326
|
+
false,
|
|
83327
|
+
node,
|
|
83328
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83329
|
+
) : exprType;
|
|
83330
|
+
const effectiveExpr = expr && getEffectiveCheckNode(expr);
|
|
83331
|
+
const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
|
|
83332
|
+
if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
|
|
83333
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83334
|
+
return;
|
|
83335
|
+
}
|
|
83336
|
+
if (checkTypeAssignableTo(
|
|
83337
|
+
unwrappedExprType,
|
|
83338
|
+
unwrappedReturnType,
|
|
83339
|
+
/*errorNode*/
|
|
83340
|
+
void 0
|
|
83341
|
+
)) {
|
|
83342
|
+
return;
|
|
83343
|
+
}
|
|
83344
|
+
let narrowPosition = node;
|
|
83345
|
+
let narrowFlowNode = inReturnStatement && node.flowNode;
|
|
83346
|
+
if (expr && isConditionalExpression(expr.parent)) {
|
|
83347
|
+
narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
|
|
83348
|
+
narrowPosition = expr;
|
|
83349
|
+
}
|
|
83350
|
+
if (!narrowFlowNode) {
|
|
83351
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83352
|
+
return;
|
|
83353
|
+
}
|
|
83354
|
+
const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
|
|
83355
|
+
container,
|
|
83356
|
+
/*includeThisTypes*/
|
|
83357
|
+
false
|
|
83358
|
+
), getEffectiveTypeParameterDeclarations(container));
|
|
83359
|
+
const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
|
|
83360
|
+
if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
|
|
83361
|
+
checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
|
|
83362
|
+
return;
|
|
83363
|
+
}
|
|
83364
|
+
const narrowedTypeParameters = [];
|
|
83365
|
+
const narrowedTypes = [];
|
|
83366
|
+
for (const [typeParam, symbol, reference] of narrowableTypeParameters) {
|
|
83367
|
+
const narrowReference = factory.cloneNode(reference);
|
|
83368
|
+
narrowReference.id = void 0;
|
|
83369
|
+
getNodeLinks(narrowReference).resolvedSymbol = symbol;
|
|
83370
|
+
setParent(narrowReference, narrowPosition.parent);
|
|
83371
|
+
narrowReference.flowNode = narrowFlowNode;
|
|
83372
|
+
const initialType = getNarrowableTypeForReference(
|
|
83373
|
+
typeParam,
|
|
83374
|
+
narrowReference,
|
|
83375
|
+
/*checkMode*/
|
|
83376
|
+
void 0,
|
|
83377
|
+
/*forReturnTypeNarrowing*/
|
|
83378
|
+
true
|
|
83379
|
+
);
|
|
83380
|
+
if (initialType === typeParam) {
|
|
83381
|
+
continue;
|
|
83382
|
+
}
|
|
83383
|
+
const flowType = getFlowTypeOfReference(narrowReference, initialType);
|
|
83384
|
+
const exprType2 = getTypeFromFlowType(flowType);
|
|
83385
|
+
if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
|
|
83386
|
+
continue;
|
|
83387
|
+
}
|
|
83388
|
+
const narrowedType = getSubstitutionType(
|
|
83389
|
+
typeParam,
|
|
83390
|
+
exprType2,
|
|
83391
|
+
/*isNarrowed*/
|
|
83392
|
+
true
|
|
83393
|
+
);
|
|
83394
|
+
narrowedTypeParameters.push(typeParam);
|
|
83395
|
+
narrowedTypes.push(narrowedType);
|
|
83396
|
+
}
|
|
83397
|
+
const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
|
|
83398
|
+
const narrowedReturnType = instantiateType(
|
|
83399
|
+
unwrappedReturnType,
|
|
83400
|
+
narrowMapper
|
|
83401
|
+
);
|
|
83402
|
+
if (expr) {
|
|
83403
|
+
const links = getNodeLinks(expr);
|
|
83404
|
+
if (!links.contextualReturnType) {
|
|
83405
|
+
links.contextualReturnType = narrowedReturnType;
|
|
83406
|
+
}
|
|
83407
|
+
}
|
|
83408
|
+
const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
|
|
83409
|
+
const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
|
|
83410
|
+
narrowedExprType,
|
|
83411
|
+
/*withAlias*/
|
|
83412
|
+
false,
|
|
83413
|
+
node,
|
|
83414
|
+
Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
|
|
83415
|
+
) : narrowedExprType;
|
|
83416
|
+
checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
|
|
83417
|
+
}
|
|
83418
|
+
function getNarrowableTypeParameters(candidates) {
|
|
83419
|
+
const narrowableParams = [];
|
|
83420
|
+
for (const typeParam of candidates) {
|
|
83421
|
+
const constraint = getConstraintOfTypeParameter(typeParam);
|
|
83422
|
+
if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
|
|
83423
|
+
if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
|
|
83424
|
+
const declaration = typeParam.symbol.declarations[0];
|
|
83425
|
+
const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
|
|
83426
|
+
if (!isFunctionLike(container)) continue;
|
|
83427
|
+
let reference;
|
|
83428
|
+
let hasInvalidReference = false;
|
|
83429
|
+
for (const paramDecl of container.parameters) {
|
|
83430
|
+
const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
|
|
83431
|
+
if (!typeNode) continue;
|
|
83432
|
+
if (isTypeParameterReferenced(typeParam, typeNode)) {
|
|
83433
|
+
let candidateReference;
|
|
83434
|
+
if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
|
|
83435
|
+
if (reference) {
|
|
83436
|
+
hasInvalidReference = true;
|
|
83437
|
+
break;
|
|
83438
|
+
}
|
|
83439
|
+
reference = candidateReference;
|
|
83440
|
+
} else {
|
|
83441
|
+
hasInvalidReference = true;
|
|
83442
|
+
break;
|
|
83443
|
+
}
|
|
83444
|
+
}
|
|
83445
|
+
}
|
|
83446
|
+
if (!hasInvalidReference && reference) {
|
|
83447
|
+
const symbol = getResolvedSymbol(reference);
|
|
83448
|
+
if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
|
|
83449
|
+
}
|
|
83450
|
+
}
|
|
83451
|
+
}
|
|
83452
|
+
return narrowableParams;
|
|
83453
|
+
function getValidParameterReference(paramDecl, constraint) {
|
|
83454
|
+
if (!isIdentifier(paramDecl.name)) return;
|
|
83455
|
+
const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
|
|
83456
|
+
if (isOptional && !containsUndefinedType(constraint)) return;
|
|
83457
|
+
return paramDecl.name;
|
|
83458
|
+
}
|
|
83459
|
+
function isReferenceToTypeParameter(typeParam, node) {
|
|
83460
|
+
return getTypeFromTypeReference(node) === typeParam;
|
|
83461
|
+
}
|
|
83462
|
+
function isTypeParameterReferenced(typeParam, node) {
|
|
83463
|
+
return isReferenced(node);
|
|
83464
|
+
function isReferenced(node2) {
|
|
83465
|
+
if (isTypeReferenceNode(node2)) {
|
|
83466
|
+
return isReferenceToTypeParameter(typeParam, node2);
|
|
83467
|
+
}
|
|
83468
|
+
if (isTypeQueryNode(node2)) {
|
|
83469
|
+
return isTypeParameterPossiblyReferenced(typeParam, node2);
|
|
83470
|
+
}
|
|
83471
|
+
return !!forEachChild(node2, isReferenced);
|
|
83472
|
+
}
|
|
83473
|
+
}
|
|
83474
|
+
}
|
|
83475
|
+
function isNarrowableReturnType(returnType) {
|
|
83476
|
+
return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
|
|
83477
|
+
}
|
|
83478
|
+
function isNarrowableConditionalType(type, mapper) {
|
|
83479
|
+
const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
|
|
83480
|
+
const mapped = getMappedType(t, mapper);
|
|
83481
|
+
if (isNarrowingSubstitutionType(mapped)) {
|
|
83482
|
+
return mapped.baseType;
|
|
83483
|
+
}
|
|
83484
|
+
return mapped;
|
|
83485
|
+
});
|
|
83486
|
+
const id = `${type.id}:${getTypeListId(typeArguments)}`;
|
|
83487
|
+
let result = narrowableReturnTypeCache.get(id);
|
|
83488
|
+
if (result === void 0) {
|
|
83489
|
+
const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
|
|
83490
|
+
const instantiatedType = instantiateType(type, nonNarrowingMapper);
|
|
83491
|
+
result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
|
|
83492
|
+
narrowableReturnTypeCache.set(id, result);
|
|
83493
|
+
}
|
|
83494
|
+
return result;
|
|
83495
|
+
}
|
|
83496
|
+
function isNarrowableConditionalTypeWorker(type) {
|
|
83497
|
+
if (!type.root.isDistributive) {
|
|
83498
|
+
return false;
|
|
83499
|
+
}
|
|
83500
|
+
if (type.root.inferTypeParameters) {
|
|
83501
|
+
return false;
|
|
83502
|
+
}
|
|
83503
|
+
if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
|
|
83504
|
+
return false;
|
|
83505
|
+
}
|
|
83506
|
+
const constraintType = getConstraintOfTypeParameter(type.checkType);
|
|
83507
|
+
if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
|
|
83508
|
+
return false;
|
|
83509
|
+
}
|
|
83510
|
+
if (!everyType(type.extendsType, (extendsType) => some(
|
|
83511
|
+
constraintType.types,
|
|
83512
|
+
(constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
|
|
83513
|
+
))) {
|
|
83514
|
+
return false;
|
|
83515
|
+
}
|
|
83516
|
+
const trueType2 = getTrueTypeFromConditionalType(type);
|
|
83517
|
+
const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
|
|
83518
|
+
if (!isValidTrueType) return false;
|
|
83519
|
+
const falseType2 = getFalseTypeFromConditionalType(type);
|
|
83520
|
+
const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
|
|
83521
|
+
return isValidFalseType;
|
|
83522
|
+
}
|
|
83523
|
+
function isConditionalType(type) {
|
|
83524
|
+
return !!(type.flags & 16777216 /* Conditional */);
|
|
83525
|
+
}
|
|
83074
83526
|
function checkWithStatement(node) {
|
|
83075
83527
|
if (!checkGrammarStatementInAmbientContext(node)) {
|
|
83076
83528
|
if (node.flags & 65536 /* AwaitContext */) {
|
|
@@ -93044,7 +93496,7 @@ function transformTypeScript(context) {
|
|
|
93044
93496
|
return updated;
|
|
93045
93497
|
}
|
|
93046
93498
|
function visitParenthesizedExpression(node) {
|
|
93047
|
-
const innerExpression = skipOuterExpressions(node.expression, ~(
|
|
93499
|
+
const innerExpression = skipOuterExpressions(node.expression, ~(38 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
|
|
93048
93500
|
if (isAssertionExpression(innerExpression) || isSatisfiesExpression(innerExpression)) {
|
|
93049
93501
|
const expression = visitNode(node.expression, visitor, isExpression);
|
|
93050
93502
|
Debug.assert(expression);
|
|
@@ -131999,18 +132451,21 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131999
132451
|
return failed;
|
|
132000
132452
|
}
|
|
132001
132453
|
function typeFromFunctionLikeExpression(fnNode, context) {
|
|
132002
|
-
const
|
|
132003
|
-
context.noInferenceFallback = true;
|
|
132004
|
-
createReturnFromSignature(
|
|
132454
|
+
const returnType = createReturnFromSignature(
|
|
132005
132455
|
fnNode,
|
|
132006
132456
|
/*symbol*/
|
|
132007
132457
|
void 0,
|
|
132008
132458
|
context
|
|
132009
132459
|
);
|
|
132010
|
-
reuseTypeParameters(fnNode.typeParameters, context);
|
|
132011
|
-
fnNode.parameters.map((p) => ensureParameter(p, context));
|
|
132012
|
-
|
|
132013
|
-
|
|
132460
|
+
const typeParameters = reuseTypeParameters(fnNode.typeParameters, context);
|
|
132461
|
+
const parameters = fnNode.parameters.map((p) => ensureParameter(p, context));
|
|
132462
|
+
return syntacticResult(
|
|
132463
|
+
factory.createFunctionTypeNode(
|
|
132464
|
+
typeParameters,
|
|
132465
|
+
parameters,
|
|
132466
|
+
returnType
|
|
132467
|
+
)
|
|
132468
|
+
);
|
|
132014
132469
|
}
|
|
132015
132470
|
function canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext) {
|
|
132016
132471
|
if (!isConstContext) {
|