typescript 4.6.0-dev.20211102 → 4.6.0-dev.20211103
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/lib.es5.d.ts +1 -1
- package/lib/tsc.js +142 -81
- package/lib/tsserver.js +193 -101
- package/lib/tsserverlibrary.js +193 -101
- package/lib/typescript.js +193 -101
- package/lib/typescriptServices.js +193 -101
- package/lib/typingsInstaller.js +193 -101
- package/package.json +1 -1
package/lib/typescript.js
CHANGED
|
@@ -294,7 +294,7 @@ var ts;
|
|
|
294
294
|
// The following is baselined as a literal template type without intervention
|
|
295
295
|
/** The version of the TypeScript compiler release */
|
|
296
296
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
297
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20211103";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -4994,6 +4994,7 @@ var ts;
|
|
|
4994
4994
|
NodeCheckFlags[NodeCheckFlags["ConstructorReferenceInClass"] = 33554432] = "ConstructorReferenceInClass";
|
|
4995
4995
|
NodeCheckFlags[NodeCheckFlags["ContainsClassWithPrivateIdentifiers"] = 67108864] = "ContainsClassWithPrivateIdentifiers";
|
|
4996
4996
|
NodeCheckFlags[NodeCheckFlags["ContainsSuperPropertyInStaticInitializer"] = 134217728] = "ContainsSuperPropertyInStaticInitializer";
|
|
4997
|
+
NodeCheckFlags[NodeCheckFlags["InCheckIdentifier"] = 268435456] = "InCheckIdentifier";
|
|
4997
4998
|
})(NodeCheckFlags = ts.NodeCheckFlags || (ts.NodeCheckFlags = {}));
|
|
4998
4999
|
var TypeFlags;
|
|
4999
5000
|
(function (TypeFlags) {
|
|
@@ -5067,8 +5068,6 @@ var ts;
|
|
|
5067
5068
|
// 'Narrowable' types are types where narrowing actually narrows.
|
|
5068
5069
|
// This *should* be every type other than null, undefined, void, and never
|
|
5069
5070
|
TypeFlags[TypeFlags["Narrowable"] = 536624127] = "Narrowable";
|
|
5070
|
-
/* @internal */
|
|
5071
|
-
TypeFlags[TypeFlags["NotPrimitiveUnion"] = 468598819] = "NotPrimitiveUnion";
|
|
5072
5071
|
// The following flags are aggregated during union and intersection type construction
|
|
5073
5072
|
/* @internal */
|
|
5074
5073
|
TypeFlags[TypeFlags["IncludesMask"] = 205258751] = "IncludesMask";
|
|
@@ -5081,6 +5080,10 @@ var ts;
|
|
|
5081
5080
|
TypeFlags[TypeFlags["IncludesWildcard"] = 8388608] = "IncludesWildcard";
|
|
5082
5081
|
/* @internal */
|
|
5083
5082
|
TypeFlags[TypeFlags["IncludesEmptyObject"] = 16777216] = "IncludesEmptyObject";
|
|
5083
|
+
/* @internal */
|
|
5084
|
+
TypeFlags[TypeFlags["IncludesInstantiable"] = 33554432] = "IncludesInstantiable";
|
|
5085
|
+
/* @internal */
|
|
5086
|
+
TypeFlags[TypeFlags["NotPrimitiveUnion"] = 36323363] = "NotPrimitiveUnion";
|
|
5084
5087
|
})(TypeFlags = ts.TypeFlags || (ts.TypeFlags = {}));
|
|
5085
5088
|
// Types included in TypeFlags.ObjectFlagsType have an objectFlags property. Some ObjectFlags
|
|
5086
5089
|
// are specific to certain types and reuse the same bit position. Those ObjectFlags require a check
|
|
@@ -8295,7 +8298,7 @@ var ts;
|
|
|
8295
8298
|
Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: diag(1321, ts.DiagnosticCategory.Error, "Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_cal_1321", "Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member."),
|
|
8296
8299
|
Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member: diag(1322, ts.DiagnosticCategory.Error, "Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_con_1322", "Type of iterated elements of a 'yield*' operand must either be a valid promise or must not contain a callable 'then' member."),
|
|
8297
8300
|
Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node12_or_nodenext: diag(1323, ts.DiagnosticCategory.Error, "Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd__1323", "Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node12', or 'nodenext'."),
|
|
8298
|
-
|
|
8301
|
+
Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_or_nodenext: diag(1324, ts.DiagnosticCategory.Error, "Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_or_nodenext_1324", "Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'."),
|
|
8299
8302
|
Argument_of_dynamic_import_cannot_be_spread_element: diag(1325, ts.DiagnosticCategory.Error, "Argument_of_dynamic_import_cannot_be_spread_element_1325", "Argument of dynamic import cannot be spread element."),
|
|
8300
8303
|
Dynamic_import_cannot_have_type_arguments: diag(1326, ts.DiagnosticCategory.Error, "Dynamic_import_cannot_have_type_arguments_1326", "Dynamic import cannot have type arguments."),
|
|
8301
8304
|
String_literal_with_double_quotes_expected: diag(1327, ts.DiagnosticCategory.Error, "String_literal_with_double_quotes_expected_1327", "String literal with double quotes expected."),
|
|
@@ -8895,11 +8898,12 @@ var ts;
|
|
|
8895
8898
|
Duplicate_identifier_0_Compiler_reserves_name_1_when_emitting_super_references_in_static_initializers: diag(2818, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_Compiler_reserves_name_1_when_emitting_super_references_in_static_initializer_2818", "Duplicate identifier '{0}'. Compiler reserves name '{1}' when emitting 'super' references in static initializers."),
|
|
8896
8899
|
Namespace_name_cannot_be_0: diag(2819, ts.DiagnosticCategory.Error, "Namespace_name_cannot_be_0_2819", "Namespace name cannot be '{0}'."),
|
|
8897
8900
|
Type_0_is_not_assignable_to_type_1_Did_you_mean_2: diag(2820, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_Did_you_mean_2_2820", "Type '{0}' is not assignable to type '{1}'. Did you mean '{2}'?"),
|
|
8898
|
-
|
|
8901
|
+
Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext: diag(2821, ts.DiagnosticCategory.Error, "Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext_2821", "Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'."),
|
|
8899
8902
|
Import_assertions_cannot_be_used_with_type_only_imports_or_exports: diag(2822, ts.DiagnosticCategory.Error, "Import_assertions_cannot_be_used_with_type_only_imports_or_exports_2822", "Import assertions cannot be used with type-only imports or exports."),
|
|
8900
8903
|
Cannot_find_namespace_0_Did_you_mean_1: diag(2833, ts.DiagnosticCategory.Error, "Cannot_find_namespace_0_Did_you_mean_1_2833", "Cannot find namespace '{0}'. Did you mean '{1}'?"),
|
|
8901
8904
|
Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_node12_or_nodenext_Consider_adding_an_extension_to_the_import_path: diag(2834, ts.DiagnosticCategory.Error, "Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_n_2834", "Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Consider adding an extension to the import path."),
|
|
8902
8905
|
Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_node12_or_nodenext_Did_you_mean_0: diag(2835, ts.DiagnosticCategory.Error, "Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_n_2835", "Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean '{0}'?"),
|
|
8906
|
+
Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."),
|
|
8903
8907
|
Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
|
|
8904
8908
|
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
|
|
8905
8909
|
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
|
|
@@ -11926,6 +11930,7 @@ var ts;
|
|
|
11926
11930
|
tokenValue = tokenValue.slice(0, -1);
|
|
11927
11931
|
pos--;
|
|
11928
11932
|
}
|
|
11933
|
+
return getIdentifierToken();
|
|
11929
11934
|
}
|
|
11930
11935
|
return token;
|
|
11931
11936
|
}
|
|
@@ -54312,12 +54317,15 @@ var ts;
|
|
|
54312
54317
|
}
|
|
54313
54318
|
/** Return the inferred type for a binding element */
|
|
54314
54319
|
function getTypeForBindingElement(declaration) {
|
|
54315
|
-
var
|
|
54316
|
-
|
|
54317
|
-
|
|
54318
|
-
|
|
54320
|
+
var parentType = getTypeForBindingElementParent(declaration.parent.parent);
|
|
54321
|
+
return parentType && getBindingElementTypeFromParentType(declaration, parentType);
|
|
54322
|
+
}
|
|
54323
|
+
function getBindingElementTypeFromParentType(declaration, parentType) {
|
|
54324
|
+
// If an any type was inferred for parent, infer that for the binding element
|
|
54325
|
+
if (isTypeAny(parentType)) {
|
|
54319
54326
|
return parentType;
|
|
54320
54327
|
}
|
|
54328
|
+
var pattern = declaration.parent;
|
|
54321
54329
|
// Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
|
|
54322
54330
|
if (strictNullChecks && declaration.flags & 8388608 /* Ambient */ && ts.isParameterDeclaration(declaration)) {
|
|
54323
54331
|
parentType = getNonNullableType(parentType);
|
|
@@ -59529,6 +59537,8 @@ var ts;
|
|
|
59529
59537
|
// We ignore 'never' types in unions
|
|
59530
59538
|
if (!(flags & 131072 /* Never */)) {
|
|
59531
59539
|
includes |= flags & 205258751 /* IncludesMask */;
|
|
59540
|
+
if (flags & 465829888 /* Instantiable */)
|
|
59541
|
+
includes |= 33554432 /* IncludesInstantiable */;
|
|
59532
59542
|
if (type === wildcardType)
|
|
59533
59543
|
includes |= 8388608 /* IncludesWildcard */;
|
|
59534
59544
|
if (!strictNullChecks && flags & 98304 /* Nullable */) {
|
|
@@ -59742,7 +59752,7 @@ var ts;
|
|
|
59742
59752
|
origin = createOriginUnionOrIntersectionType(1048576 /* Union */, reducedTypes);
|
|
59743
59753
|
}
|
|
59744
59754
|
}
|
|
59745
|
-
var objectFlags = (includes &
|
|
59755
|
+
var objectFlags = (includes & 36323363 /* NotPrimitiveUnion */ ? 0 : 65536 /* PrimitiveUnion */) |
|
|
59746
59756
|
(includes & 2097152 /* Intersection */ ? 33554432 /* ContainsIntersections */ : 0);
|
|
59747
59757
|
return getUnionTypeFromSortedList(typeSet, objectFlags, aliasSymbol, aliasTypeArguments, origin);
|
|
59748
59758
|
}
|
|
@@ -62937,7 +62947,7 @@ var ts;
|
|
|
62937
62947
|
return true;
|
|
62938
62948
|
}
|
|
62939
62949
|
if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
|
|
62940
|
-
var related = relation.get(getRelationKey(source, target, 0 /* None */, relation));
|
|
62950
|
+
var related = relation.get(getRelationKey(source, target, 0 /* None */, relation, /*ignoreConstraints*/ false));
|
|
62941
62951
|
if (related !== undefined) {
|
|
62942
62952
|
return !!(related & 1 /* Succeeded */);
|
|
62943
62953
|
}
|
|
@@ -63786,7 +63796,8 @@ var ts;
|
|
|
63786
63796
|
if (overflow) {
|
|
63787
63797
|
return 0 /* False */;
|
|
63788
63798
|
}
|
|
63789
|
-
var
|
|
63799
|
+
var keyIntersectionState = intersectionState | (inPropertyCheck ? 16 /* InPropertyCheck */ : 0);
|
|
63800
|
+
var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
|
|
63790
63801
|
var entry = relation.get(id);
|
|
63791
63802
|
if (entry !== undefined) {
|
|
63792
63803
|
if (reportErrors && entry & 2 /* Failed */ && !(entry & 4 /* Reported */)) {
|
|
@@ -63813,16 +63824,13 @@ var ts;
|
|
|
63813
63824
|
targetStack = [];
|
|
63814
63825
|
}
|
|
63815
63826
|
else {
|
|
63816
|
-
//
|
|
63817
|
-
//
|
|
63818
|
-
//
|
|
63819
|
-
var broadestEquivalentId = id.
|
|
63820
|
-
var index = ts.length(id.slice(0, offset).match(/[-=]/g) || undefined);
|
|
63821
|
-
return "=" + index;
|
|
63822
|
-
}); }).join(",");
|
|
63827
|
+
// A key that starts with "*" is an indication that we have type references that reference constrained
|
|
63828
|
+
// type parameters. For such keys we also check against the key we would have gotten if all type parameters
|
|
63829
|
+
// were unconstrained.
|
|
63830
|
+
var broadestEquivalentId = id.startsWith("*") ? getRelationKey(source, target, keyIntersectionState, relation, /*ignoreConstraints*/ true) : undefined;
|
|
63823
63831
|
for (var i = 0; i < maybeCount; i++) {
|
|
63824
63832
|
// If source and target are already being compared, consider them related with assumptions
|
|
63825
|
-
if (id === maybeKeys[i] || broadestEquivalentId === maybeKeys[i]) {
|
|
63833
|
+
if (id === maybeKeys[i] || broadestEquivalentId && broadestEquivalentId === maybeKeys[i]) {
|
|
63826
63834
|
return 3 /* Maybe */;
|
|
63827
63835
|
}
|
|
63828
63836
|
}
|
|
@@ -64117,7 +64125,7 @@ var ts;
|
|
|
64117
64125
|
originalErrorInfo = undefined;
|
|
64118
64126
|
}
|
|
64119
64127
|
}
|
|
64120
|
-
else if (isGenericMappedType(target)) {
|
|
64128
|
+
else if (isGenericMappedType(target) && relation !== identityRelation) {
|
|
64121
64129
|
// Check if source type `S` is related to target type `{ [P in Q]: T }` or `{ [P in Q as R]: T}`.
|
|
64122
64130
|
var keysRemapped = !!target.declaration.nameType;
|
|
64123
64131
|
var templateType = getTemplateTypeFromMappedType(target);
|
|
@@ -65329,48 +65337,56 @@ var ts;
|
|
|
65329
65337
|
function isTypeReferenceWithGenericArguments(type) {
|
|
65330
65338
|
return isNonDeferredTypeReference(type) && ts.some(getTypeArguments(type), function (t) { return !!(t.flags & 262144 /* TypeParameter */) || isTypeReferenceWithGenericArguments(t); });
|
|
65331
65339
|
}
|
|
65332
|
-
|
|
65333
|
-
|
|
65334
|
-
|
|
65335
|
-
|
|
65336
|
-
|
|
65337
|
-
|
|
65338
|
-
|
|
65339
|
-
|
|
65340
|
-
|
|
65341
|
-
if (
|
|
65342
|
-
|
|
65343
|
-
|
|
65344
|
-
|
|
65345
|
-
|
|
65340
|
+
function getGenericTypeReferenceRelationKey(source, target, postFix, ignoreConstraints) {
|
|
65341
|
+
var typeParameters = [];
|
|
65342
|
+
var constraintMarker = "";
|
|
65343
|
+
var sourceId = getTypeReferenceId(source, 0);
|
|
65344
|
+
var targetId = getTypeReferenceId(target, 0);
|
|
65345
|
+
return "" + constraintMarker + sourceId + "," + targetId + postFix;
|
|
65346
|
+
// getTypeReferenceId(A<T, number, U>) returns "111=0-12=1"
|
|
65347
|
+
// where A.id=111 and number.id=12
|
|
65348
|
+
function getTypeReferenceId(type, depth) {
|
|
65349
|
+
if (depth === void 0) { depth = 0; }
|
|
65350
|
+
var result = "" + type.target.id;
|
|
65351
|
+
for (var _i = 0, _a = getTypeArguments(type); _i < _a.length; _i++) {
|
|
65352
|
+
var t = _a[_i];
|
|
65353
|
+
if (t.flags & 262144 /* TypeParameter */) {
|
|
65354
|
+
if (ignoreConstraints || isUnconstrainedTypeParameter(t)) {
|
|
65355
|
+
var index = typeParameters.indexOf(t);
|
|
65356
|
+
if (index < 0) {
|
|
65357
|
+
index = typeParameters.length;
|
|
65358
|
+
typeParameters.push(t);
|
|
65359
|
+
}
|
|
65360
|
+
result += "=" + index;
|
|
65361
|
+
continue;
|
|
65362
|
+
}
|
|
65363
|
+
// We mark type references that reference constrained type parameters such that we know to obtain
|
|
65364
|
+
// and look for a "broadest equivalent key" in the cache.
|
|
65365
|
+
constraintMarker = "*";
|
|
65366
|
+
}
|
|
65367
|
+
else if (depth < 4 && isTypeReferenceWithGenericArguments(t)) {
|
|
65368
|
+
result += "<" + getTypeReferenceId(t, depth + 1) + ">";
|
|
65369
|
+
continue;
|
|
65346
65370
|
}
|
|
65347
|
-
result += "=" + index;
|
|
65348
|
-
}
|
|
65349
|
-
else if (depth < 4 && isTypeReferenceWithGenericArguments(t)) {
|
|
65350
|
-
result += "<" + getTypeReferenceId(t, typeParameters, depth + 1) + ">";
|
|
65351
|
-
}
|
|
65352
|
-
else {
|
|
65353
65371
|
result += "-" + t.id;
|
|
65354
65372
|
}
|
|
65373
|
+
return result;
|
|
65355
65374
|
}
|
|
65356
|
-
return result;
|
|
65357
65375
|
}
|
|
65358
65376
|
/**
|
|
65359
65377
|
* To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters.
|
|
65360
65378
|
* For other cases, the types ids are used.
|
|
65361
65379
|
*/
|
|
65362
|
-
function getRelationKey(source, target, intersectionState, relation) {
|
|
65380
|
+
function getRelationKey(source, target, intersectionState, relation, ignoreConstraints) {
|
|
65363
65381
|
if (relation === identityRelation && source.id > target.id) {
|
|
65364
65382
|
var temp = source;
|
|
65365
65383
|
source = target;
|
|
65366
65384
|
target = temp;
|
|
65367
65385
|
}
|
|
65368
65386
|
var postFix = intersectionState ? ":" + intersectionState : "";
|
|
65369
|
-
|
|
65370
|
-
|
|
65371
|
-
|
|
65372
|
-
}
|
|
65373
|
-
return source.id + "," + target.id + postFix;
|
|
65387
|
+
return isTypeReferenceWithGenericArguments(source) && isTypeReferenceWithGenericArguments(target) ?
|
|
65388
|
+
getGenericTypeReferenceRelationKey(source, target, postFix, ignoreConstraints) :
|
|
65389
|
+
source.id + "," + target.id + postFix;
|
|
65374
65390
|
}
|
|
65375
65391
|
// Invoke the callback for each underlying property symbol of the given symbol and return the first
|
|
65376
65392
|
// value that isn't undefined.
|
|
@@ -65418,28 +65434,35 @@ var ts;
|
|
|
65418
65434
|
!hasBaseType(checkClass, getDeclaringClass(p)) : false; }) ? undefined : checkClass;
|
|
65419
65435
|
}
|
|
65420
65436
|
// Return true if the given type is deeply nested. We consider this to be the case when structural type comparisons
|
|
65421
|
-
// for
|
|
65437
|
+
// for maxDepth or more occurrences or instantiations of the type have been recorded on the given stack. It is possible,
|
|
65422
65438
|
// though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely
|
|
65423
|
-
// expanding. Effectively, we will generate a false positive when two types are structurally equal to at least
|
|
65439
|
+
// expanding. Effectively, we will generate a false positive when two types are structurally equal to at least maxDepth
|
|
65424
65440
|
// levels, but unequal at some level beyond that.
|
|
65425
|
-
// In addition, this will also detect when an indexed access has been chained off of
|
|
65426
|
-
// the dual of the structural comparison), and likewise mark the type as deeply nested, potentially adding
|
|
65427
|
-
// for finite but deeply expanding indexed accesses (eg, for `Q[P1][P2][P3][P4][P5]`).
|
|
65428
|
-
// It also detects when a recursive type reference has expanded
|
|
65441
|
+
// In addition, this will also detect when an indexed access has been chained off of maxDepth more times (which is
|
|
65442
|
+
// essentially the dual of the structural comparison), and likewise mark the type as deeply nested, potentially adding
|
|
65443
|
+
// false positives for finite but deeply expanding indexed accesses (eg, for `Q[P1][P2][P3][P4][P5]`).
|
|
65444
|
+
// It also detects when a recursive type reference has expanded maxDepth or more times, e.g. if the true branch of
|
|
65429
65445
|
// `type A<T> = null extends T ? [A<NonNullable<T>>] : [T]`
|
|
65430
|
-
// has expanded into `[A<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>>>>>>]
|
|
65431
|
-
//
|
|
65446
|
+
// has expanded into `[A<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>>>>>>]`. In such cases we need
|
|
65447
|
+
// to terminate the expansion, and we do so here.
|
|
65432
65448
|
function isDeeplyNestedType(type, stack, depth, maxDepth) {
|
|
65433
|
-
if (maxDepth === void 0) { maxDepth =
|
|
65449
|
+
if (maxDepth === void 0) { maxDepth = 3; }
|
|
65434
65450
|
if (depth >= maxDepth) {
|
|
65435
65451
|
var identity_1 = getRecursionIdentity(type);
|
|
65436
65452
|
var count = 0;
|
|
65453
|
+
var lastTypeId = 0;
|
|
65437
65454
|
for (var i = 0; i < depth; i++) {
|
|
65438
|
-
|
|
65439
|
-
|
|
65440
|
-
|
|
65441
|
-
|
|
65455
|
+
var t = stack[i];
|
|
65456
|
+
if (getRecursionIdentity(t) === identity_1) {
|
|
65457
|
+
// We only count occurrences with a higher type id than the previous occurrence, since higher
|
|
65458
|
+
// type ids are an indicator of newer instantiations caused by recursion.
|
|
65459
|
+
if (t.id >= lastTypeId) {
|
|
65460
|
+
count++;
|
|
65461
|
+
if (count >= maxDepth) {
|
|
65462
|
+
return true;
|
|
65463
|
+
}
|
|
65442
65464
|
}
|
|
65465
|
+
lastTypeId = t.id;
|
|
65443
65466
|
}
|
|
65444
65467
|
}
|
|
65445
65468
|
}
|
|
@@ -67544,29 +67567,6 @@ var ts;
|
|
|
67544
67567
|
}
|
|
67545
67568
|
return false;
|
|
67546
67569
|
}
|
|
67547
|
-
function getPropertyAccess(expr) {
|
|
67548
|
-
if (ts.isAccessExpression(expr)) {
|
|
67549
|
-
return expr;
|
|
67550
|
-
}
|
|
67551
|
-
if (ts.isIdentifier(expr)) {
|
|
67552
|
-
var symbol = getResolvedSymbol(expr);
|
|
67553
|
-
if (isConstVariable(symbol)) {
|
|
67554
|
-
var declaration = symbol.valueDeclaration;
|
|
67555
|
-
// Given 'const x = obj.kind', allow 'x' as an alias for 'obj.kind'
|
|
67556
|
-
if (ts.isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && ts.isAccessExpression(declaration.initializer)) {
|
|
67557
|
-
return declaration.initializer;
|
|
67558
|
-
}
|
|
67559
|
-
// Given 'const { kind: x } = obj', allow 'x' as an alias for 'obj.kind'
|
|
67560
|
-
if (ts.isBindingElement(declaration) && !declaration.initializer) {
|
|
67561
|
-
var parent = declaration.parent.parent;
|
|
67562
|
-
if (ts.isVariableDeclaration(parent) && !parent.type && parent.initializer && (ts.isIdentifier(parent.initializer) || ts.isAccessExpression(parent.initializer))) {
|
|
67563
|
-
return declaration;
|
|
67564
|
-
}
|
|
67565
|
-
}
|
|
67566
|
-
}
|
|
67567
|
-
}
|
|
67568
|
-
return undefined;
|
|
67569
|
-
}
|
|
67570
67570
|
function getAccessedPropertyName(access) {
|
|
67571
67571
|
var propertyName;
|
|
67572
67572
|
return access.kind === 205 /* PropertyAccessExpression */ ? access.name.escapedText :
|
|
@@ -68465,20 +68465,21 @@ var ts;
|
|
|
68465
68465
|
}
|
|
68466
68466
|
return false;
|
|
68467
68467
|
}
|
|
68468
|
-
function getFlowTypeOfReference(reference, declaredType, initialType, flowContainer) {
|
|
68468
|
+
function getFlowTypeOfReference(reference, declaredType, initialType, flowContainer, flowNode) {
|
|
68469
68469
|
if (initialType === void 0) { initialType = declaredType; }
|
|
68470
|
+
if (flowNode === void 0) { flowNode = reference.flowNode; }
|
|
68470
68471
|
var key;
|
|
68471
68472
|
var isKeySet = false;
|
|
68472
68473
|
var flowDepth = 0;
|
|
68473
68474
|
if (flowAnalysisDisabled) {
|
|
68474
68475
|
return errorType;
|
|
68475
68476
|
}
|
|
68476
|
-
if (!
|
|
68477
|
+
if (!flowNode) {
|
|
68477
68478
|
return declaredType;
|
|
68478
68479
|
}
|
|
68479
68480
|
flowInvocationCount++;
|
|
68480
68481
|
var sharedFlowStart = sharedFlowCount;
|
|
68481
|
-
var evolvedType = getTypeFromFlowType(getTypeAtFlowNode(
|
|
68482
|
+
var evolvedType = getTypeFromFlowType(getTypeAtFlowNode(flowNode));
|
|
68482
68483
|
sharedFlowCount = sharedFlowStart;
|
|
68483
68484
|
// When the reference is 'x' in an 'x.length', 'x.push(value)', 'x.unshift(value)' or x[n] = value' operation,
|
|
68484
68485
|
// we give type 'any[]' to 'x' instead of using the type determined by control flow analysis such that operations
|
|
@@ -68910,13 +68911,57 @@ var ts;
|
|
|
68910
68911
|
}
|
|
68911
68912
|
return result;
|
|
68912
68913
|
}
|
|
68914
|
+
function getCandidateDiscriminantPropertyAccess(expr) {
|
|
68915
|
+
if (ts.isBindingPattern(reference)) {
|
|
68916
|
+
// When the reference is a binding pattern, we are narrowing a pesudo-reference in getNarrowedTypeOfSymbol.
|
|
68917
|
+
// An identifier for a destructuring variable declared in the same binding pattern is a candidate.
|
|
68918
|
+
if (ts.isIdentifier(expr)) {
|
|
68919
|
+
var symbol = getResolvedSymbol(expr);
|
|
68920
|
+
var declaration = symbol.valueDeclaration;
|
|
68921
|
+
if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && reference === declaration.parent) {
|
|
68922
|
+
return declaration;
|
|
68923
|
+
}
|
|
68924
|
+
}
|
|
68925
|
+
}
|
|
68926
|
+
else if (ts.isAccessExpression(expr)) {
|
|
68927
|
+
// An access expression is a candidate if the reference matches the left hand expression.
|
|
68928
|
+
if (isMatchingReference(reference, expr.expression)) {
|
|
68929
|
+
return expr;
|
|
68930
|
+
}
|
|
68931
|
+
}
|
|
68932
|
+
else if (ts.isIdentifier(expr)) {
|
|
68933
|
+
var symbol = getResolvedSymbol(expr);
|
|
68934
|
+
if (isConstVariable(symbol)) {
|
|
68935
|
+
var declaration = symbol.valueDeclaration;
|
|
68936
|
+
// Given 'const x = obj.kind', allow 'x' as an alias for 'obj.kind'
|
|
68937
|
+
if (ts.isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && ts.isAccessExpression(declaration.initializer) &&
|
|
68938
|
+
isMatchingReference(reference, declaration.initializer.expression)) {
|
|
68939
|
+
return declaration.initializer;
|
|
68940
|
+
}
|
|
68941
|
+
// Given 'const { kind: x } = obj', allow 'x' as an alias for 'obj.kind'
|
|
68942
|
+
if (ts.isBindingElement(declaration) && !declaration.initializer) {
|
|
68943
|
+
var parent = declaration.parent.parent;
|
|
68944
|
+
if (ts.isVariableDeclaration(parent) && !parent.type && parent.initializer && (ts.isIdentifier(parent.initializer) || ts.isAccessExpression(parent.initializer)) &&
|
|
68945
|
+
isMatchingReference(reference, parent.initializer)) {
|
|
68946
|
+
return declaration;
|
|
68947
|
+
}
|
|
68948
|
+
}
|
|
68949
|
+
}
|
|
68950
|
+
}
|
|
68951
|
+
return undefined;
|
|
68952
|
+
}
|
|
68913
68953
|
function getDiscriminantPropertyAccess(expr, computedType) {
|
|
68914
|
-
var access, name;
|
|
68915
68954
|
var type = declaredType.flags & 1048576 /* Union */ ? declaredType : computedType;
|
|
68916
|
-
|
|
68917
|
-
|
|
68918
|
-
|
|
68919
|
-
|
|
68955
|
+
if (type.flags & 1048576 /* Union */) {
|
|
68956
|
+
var access = getCandidateDiscriminantPropertyAccess(expr);
|
|
68957
|
+
if (access) {
|
|
68958
|
+
var name = getAccessedPropertyName(access);
|
|
68959
|
+
if (name && isDiscriminantProperty(type, name)) {
|
|
68960
|
+
return access;
|
|
68961
|
+
}
|
|
68962
|
+
}
|
|
68963
|
+
}
|
|
68964
|
+
return undefined;
|
|
68920
68965
|
}
|
|
68921
68966
|
function narrowTypeByDiscriminant(type, access, narrowType) {
|
|
68922
68967
|
var propName = getAccessedPropertyName(access);
|
|
@@ -69674,6 +69719,49 @@ var ts;
|
|
|
69674
69719
|
}
|
|
69675
69720
|
}
|
|
69676
69721
|
}
|
|
69722
|
+
function getNarrowedTypeOfSymbol(symbol, location) {
|
|
69723
|
+
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69724
|
+
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69725
|
+
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69726
|
+
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69727
|
+
// other binding elements from the same destructuring. Consider:
|
|
69728
|
+
//
|
|
69729
|
+
// type Action =
|
|
69730
|
+
// | { kind: 'A', payload: number }
|
|
69731
|
+
// | { kind: 'B', payload: string };
|
|
69732
|
+
//
|
|
69733
|
+
// function f1({ kind, payload }: Action) {
|
|
69734
|
+
// if (kind === 'A') {
|
|
69735
|
+
// payload.toFixed();
|
|
69736
|
+
// }
|
|
69737
|
+
// if (kind === 'B') {
|
|
69738
|
+
// payload.toUpperCase();
|
|
69739
|
+
// }
|
|
69740
|
+
// }
|
|
69741
|
+
//
|
|
69742
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69743
|
+
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69744
|
+
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69745
|
+
// destructuring from the narrowed parent type.
|
|
69746
|
+
var declaration = symbol.valueDeclaration;
|
|
69747
|
+
if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
|
|
69748
|
+
var parent = declaration.parent.parent;
|
|
69749
|
+
if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
|
|
69750
|
+
var links = getNodeLinks(location);
|
|
69751
|
+
if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
|
|
69752
|
+
links.flags |= 268435456 /* InCheckIdentifier */;
|
|
69753
|
+
var parentType = getTypeForBindingElementParent(parent);
|
|
69754
|
+
links.flags &= ~268435456 /* InCheckIdentifier */;
|
|
69755
|
+
if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
|
|
69756
|
+
var pattern = declaration.parent;
|
|
69757
|
+
var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
|
|
69758
|
+
return getBindingElementTypeFromParentType(declaration, narrowedType);
|
|
69759
|
+
}
|
|
69760
|
+
}
|
|
69761
|
+
}
|
|
69762
|
+
}
|
|
69763
|
+
return getTypeOfSymbol(symbol);
|
|
69764
|
+
}
|
|
69677
69765
|
function checkIdentifier(node, checkMode) {
|
|
69678
69766
|
var symbol = getResolvedSymbol(node);
|
|
69679
69767
|
if (symbol === unknownSymbol) {
|
|
@@ -69747,7 +69835,7 @@ var ts;
|
|
|
69747
69835
|
}
|
|
69748
69836
|
}
|
|
69749
69837
|
checkNestedBlockScopedBinding(node, symbol);
|
|
69750
|
-
var type =
|
|
69838
|
+
var type = getNarrowedTypeOfSymbol(localOrExportSymbol, node);
|
|
69751
69839
|
var assignmentKind = ts.getAssignmentTargetKind(node);
|
|
69752
69840
|
if (assignmentKind) {
|
|
69753
69841
|
if (!(localOrExportSymbol.flags & 3 /* Variable */) &&
|
|
@@ -70790,13 +70878,13 @@ var ts;
|
|
|
70790
70878
|
function isCircularMappedProperty(symbol) {
|
|
70791
70879
|
return !!(ts.getCheckFlags(symbol) & 262144 /* Mapped */ && !symbol.type && findResolutionCycleStartIndex(symbol, 0 /* Type */) >= 0);
|
|
70792
70880
|
}
|
|
70793
|
-
function getTypeOfPropertyOfContextualType(type, name) {
|
|
70881
|
+
function getTypeOfPropertyOfContextualType(type, name, nameType) {
|
|
70794
70882
|
return mapType(type, function (t) {
|
|
70795
70883
|
var _a;
|
|
70796
70884
|
if (isGenericMappedType(t)) {
|
|
70797
70885
|
var constraint = getConstraintTypeFromMappedType(t);
|
|
70798
70886
|
var constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
|
|
70799
|
-
var propertyNameType = getStringLiteralType(ts.unescapeLeadingUnderscores(name));
|
|
70887
|
+
var propertyNameType = nameType || getStringLiteralType(ts.unescapeLeadingUnderscores(name));
|
|
70800
70888
|
if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
|
|
70801
70889
|
return substituteIndexedMappedType(t, propertyNameType);
|
|
70802
70890
|
}
|
|
@@ -70812,7 +70900,7 @@ var ts;
|
|
|
70812
70900
|
return restType;
|
|
70813
70901
|
}
|
|
70814
70902
|
}
|
|
70815
|
-
return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), getStringLiteralType(ts.unescapeLeadingUnderscores(name)))) === null || _a === void 0 ? void 0 : _a.type;
|
|
70903
|
+
return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(ts.unescapeLeadingUnderscores(name)))) === null || _a === void 0 ? void 0 : _a.type;
|
|
70816
70904
|
}
|
|
70817
70905
|
return undefined;
|
|
70818
70906
|
}, /*noReductions*/ true);
|
|
@@ -70840,7 +70928,8 @@ var ts;
|
|
|
70840
70928
|
// For a (non-symbol) computed property, there is no reason to look up the name
|
|
70841
70929
|
// in the type. It will just be "__computed", which does not appear in any
|
|
70842
70930
|
// SymbolTable.
|
|
70843
|
-
|
|
70931
|
+
var symbol = getSymbolOfNode(element);
|
|
70932
|
+
return getTypeOfPropertyOfContextualType(type, symbol.escapedName, getSymbolLinks(symbol).nameType);
|
|
70844
70933
|
}
|
|
70845
70934
|
if (element.name) {
|
|
70846
70935
|
var nameType_2 = getLiteralTypeFromPropertyName(element.name);
|
|
@@ -82963,8 +83052,11 @@ var ts;
|
|
|
82963
83052
|
function checkAssertClause(declaration) {
|
|
82964
83053
|
var _a;
|
|
82965
83054
|
if (declaration.assertClause) {
|
|
82966
|
-
|
|
82967
|
-
|
|
83055
|
+
var mode = (moduleKind === ts.ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
|
|
83056
|
+
if (mode !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.ESNext) {
|
|
83057
|
+
return grammarErrorOnNode(declaration.assertClause, moduleKind === ts.ModuleKind.NodeNext
|
|
83058
|
+
? ts.Diagnostics.Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls
|
|
83059
|
+
: ts.Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext);
|
|
82968
83060
|
}
|
|
82969
83061
|
if (ts.isImportDeclaration(declaration) ? (_a = declaration.importClause) === null || _a === void 0 ? void 0 : _a.isTypeOnly : declaration.isTypeOnly) {
|
|
82970
83062
|
return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports);
|
|
@@ -86811,12 +86903,12 @@ var ts;
|
|
|
86811
86903
|
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_cannot_have_type_arguments);
|
|
86812
86904
|
}
|
|
86813
86905
|
var nodeArguments = node.arguments;
|
|
86814
|
-
if (moduleKind !== ts.ModuleKind.ESNext) {
|
|
86906
|
+
if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) {
|
|
86815
86907
|
// We are allowed trailing comma after proposal-import-assertions.
|
|
86816
86908
|
checkGrammarForDisallowedTrailingComma(nodeArguments);
|
|
86817
86909
|
if (nodeArguments.length > 1) {
|
|
86818
86910
|
var assertionArgument = nodeArguments[1];
|
|
86819
|
-
return grammarErrorOnNode(assertionArgument, ts.Diagnostics.
|
|
86911
|
+
return grammarErrorOnNode(assertionArgument, ts.Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_or_nodenext);
|
|
86820
86912
|
}
|
|
86821
86913
|
}
|
|
86822
86914
|
if (nodeArguments.length === 0 || nodeArguments.length > 2) {
|