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/tsserver.js
CHANGED
|
@@ -100,7 +100,7 @@ var ts;
|
|
|
100
100
|
// The following is baselined as a literal template type without intervention
|
|
101
101
|
/** The version of the TypeScript compiler release */
|
|
102
102
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
103
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
103
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20211103";
|
|
104
104
|
/* @internal */
|
|
105
105
|
var Comparison;
|
|
106
106
|
(function (Comparison) {
|
|
@@ -4800,6 +4800,7 @@ var ts;
|
|
|
4800
4800
|
NodeCheckFlags[NodeCheckFlags["ConstructorReferenceInClass"] = 33554432] = "ConstructorReferenceInClass";
|
|
4801
4801
|
NodeCheckFlags[NodeCheckFlags["ContainsClassWithPrivateIdentifiers"] = 67108864] = "ContainsClassWithPrivateIdentifiers";
|
|
4802
4802
|
NodeCheckFlags[NodeCheckFlags["ContainsSuperPropertyInStaticInitializer"] = 134217728] = "ContainsSuperPropertyInStaticInitializer";
|
|
4803
|
+
NodeCheckFlags[NodeCheckFlags["InCheckIdentifier"] = 268435456] = "InCheckIdentifier";
|
|
4803
4804
|
})(NodeCheckFlags = ts.NodeCheckFlags || (ts.NodeCheckFlags = {}));
|
|
4804
4805
|
var TypeFlags;
|
|
4805
4806
|
(function (TypeFlags) {
|
|
@@ -4873,8 +4874,6 @@ var ts;
|
|
|
4873
4874
|
// 'Narrowable' types are types where narrowing actually narrows.
|
|
4874
4875
|
// This *should* be every type other than null, undefined, void, and never
|
|
4875
4876
|
TypeFlags[TypeFlags["Narrowable"] = 536624127] = "Narrowable";
|
|
4876
|
-
/* @internal */
|
|
4877
|
-
TypeFlags[TypeFlags["NotPrimitiveUnion"] = 468598819] = "NotPrimitiveUnion";
|
|
4878
4877
|
// The following flags are aggregated during union and intersection type construction
|
|
4879
4878
|
/* @internal */
|
|
4880
4879
|
TypeFlags[TypeFlags["IncludesMask"] = 205258751] = "IncludesMask";
|
|
@@ -4887,6 +4886,10 @@ var ts;
|
|
|
4887
4886
|
TypeFlags[TypeFlags["IncludesWildcard"] = 8388608] = "IncludesWildcard";
|
|
4888
4887
|
/* @internal */
|
|
4889
4888
|
TypeFlags[TypeFlags["IncludesEmptyObject"] = 16777216] = "IncludesEmptyObject";
|
|
4889
|
+
/* @internal */
|
|
4890
|
+
TypeFlags[TypeFlags["IncludesInstantiable"] = 33554432] = "IncludesInstantiable";
|
|
4891
|
+
/* @internal */
|
|
4892
|
+
TypeFlags[TypeFlags["NotPrimitiveUnion"] = 36323363] = "NotPrimitiveUnion";
|
|
4890
4893
|
})(TypeFlags = ts.TypeFlags || (ts.TypeFlags = {}));
|
|
4891
4894
|
// Types included in TypeFlags.ObjectFlagsType have an objectFlags property. Some ObjectFlags
|
|
4892
4895
|
// are specific to certain types and reuse the same bit position. Those ObjectFlags require a check
|
|
@@ -8101,7 +8104,7 @@ var ts;
|
|
|
8101
8104
|
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."),
|
|
8102
8105
|
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."),
|
|
8103
8106
|
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'."),
|
|
8104
|
-
|
|
8107
|
+
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'."),
|
|
8105
8108
|
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."),
|
|
8106
8109
|
Dynamic_import_cannot_have_type_arguments: diag(1326, ts.DiagnosticCategory.Error, "Dynamic_import_cannot_have_type_arguments_1326", "Dynamic import cannot have type arguments."),
|
|
8107
8110
|
String_literal_with_double_quotes_expected: diag(1327, ts.DiagnosticCategory.Error, "String_literal_with_double_quotes_expected_1327", "String literal with double quotes expected."),
|
|
@@ -8701,11 +8704,12 @@ var ts;
|
|
|
8701
8704
|
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."),
|
|
8702
8705
|
Namespace_name_cannot_be_0: diag(2819, ts.DiagnosticCategory.Error, "Namespace_name_cannot_be_0_2819", "Namespace name cannot be '{0}'."),
|
|
8703
8706
|
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}'?"),
|
|
8704
|
-
|
|
8707
|
+
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'."),
|
|
8705
8708
|
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."),
|
|
8706
8709
|
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}'?"),
|
|
8707
8710
|
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."),
|
|
8708
8711
|
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}'?"),
|
|
8712
|
+
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."),
|
|
8709
8713
|
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}'."),
|
|
8710
8714
|
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}'."),
|
|
8711
8715
|
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}'."),
|
|
@@ -11732,6 +11736,7 @@ var ts;
|
|
|
11732
11736
|
tokenValue = tokenValue.slice(0, -1);
|
|
11733
11737
|
pos--;
|
|
11734
11738
|
}
|
|
11739
|
+
return getIdentifierToken();
|
|
11735
11740
|
}
|
|
11736
11741
|
return token;
|
|
11737
11742
|
}
|
|
@@ -54118,12 +54123,15 @@ var ts;
|
|
|
54118
54123
|
}
|
|
54119
54124
|
/** Return the inferred type for a binding element */
|
|
54120
54125
|
function getTypeForBindingElement(declaration) {
|
|
54121
|
-
var
|
|
54122
|
-
|
|
54123
|
-
|
|
54124
|
-
|
|
54126
|
+
var parentType = getTypeForBindingElementParent(declaration.parent.parent);
|
|
54127
|
+
return parentType && getBindingElementTypeFromParentType(declaration, parentType);
|
|
54128
|
+
}
|
|
54129
|
+
function getBindingElementTypeFromParentType(declaration, parentType) {
|
|
54130
|
+
// If an any type was inferred for parent, infer that for the binding element
|
|
54131
|
+
if (isTypeAny(parentType)) {
|
|
54125
54132
|
return parentType;
|
|
54126
54133
|
}
|
|
54134
|
+
var pattern = declaration.parent;
|
|
54127
54135
|
// Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
|
|
54128
54136
|
if (strictNullChecks && declaration.flags & 8388608 /* Ambient */ && ts.isParameterDeclaration(declaration)) {
|
|
54129
54137
|
parentType = getNonNullableType(parentType);
|
|
@@ -59335,6 +59343,8 @@ var ts;
|
|
|
59335
59343
|
// We ignore 'never' types in unions
|
|
59336
59344
|
if (!(flags & 131072 /* Never */)) {
|
|
59337
59345
|
includes |= flags & 205258751 /* IncludesMask */;
|
|
59346
|
+
if (flags & 465829888 /* Instantiable */)
|
|
59347
|
+
includes |= 33554432 /* IncludesInstantiable */;
|
|
59338
59348
|
if (type === wildcardType)
|
|
59339
59349
|
includes |= 8388608 /* IncludesWildcard */;
|
|
59340
59350
|
if (!strictNullChecks && flags & 98304 /* Nullable */) {
|
|
@@ -59548,7 +59558,7 @@ var ts;
|
|
|
59548
59558
|
origin = createOriginUnionOrIntersectionType(1048576 /* Union */, reducedTypes);
|
|
59549
59559
|
}
|
|
59550
59560
|
}
|
|
59551
|
-
var objectFlags = (includes &
|
|
59561
|
+
var objectFlags = (includes & 36323363 /* NotPrimitiveUnion */ ? 0 : 65536 /* PrimitiveUnion */) |
|
|
59552
59562
|
(includes & 2097152 /* Intersection */ ? 33554432 /* ContainsIntersections */ : 0);
|
|
59553
59563
|
return getUnionTypeFromSortedList(typeSet, objectFlags, aliasSymbol, aliasTypeArguments, origin);
|
|
59554
59564
|
}
|
|
@@ -62743,7 +62753,7 @@ var ts;
|
|
|
62743
62753
|
return true;
|
|
62744
62754
|
}
|
|
62745
62755
|
if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
|
|
62746
|
-
var related = relation.get(getRelationKey(source, target, 0 /* None */, relation));
|
|
62756
|
+
var related = relation.get(getRelationKey(source, target, 0 /* None */, relation, /*ignoreConstraints*/ false));
|
|
62747
62757
|
if (related !== undefined) {
|
|
62748
62758
|
return !!(related & 1 /* Succeeded */);
|
|
62749
62759
|
}
|
|
@@ -63592,7 +63602,8 @@ var ts;
|
|
|
63592
63602
|
if (overflow) {
|
|
63593
63603
|
return 0 /* False */;
|
|
63594
63604
|
}
|
|
63595
|
-
var
|
|
63605
|
+
var keyIntersectionState = intersectionState | (inPropertyCheck ? 16 /* InPropertyCheck */ : 0);
|
|
63606
|
+
var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
|
|
63596
63607
|
var entry = relation.get(id);
|
|
63597
63608
|
if (entry !== undefined) {
|
|
63598
63609
|
if (reportErrors && entry & 2 /* Failed */ && !(entry & 4 /* Reported */)) {
|
|
@@ -63619,16 +63630,13 @@ var ts;
|
|
|
63619
63630
|
targetStack = [];
|
|
63620
63631
|
}
|
|
63621
63632
|
else {
|
|
63622
|
-
//
|
|
63623
|
-
//
|
|
63624
|
-
//
|
|
63625
|
-
var broadestEquivalentId = id.
|
|
63626
|
-
var index = ts.length(id.slice(0, offset).match(/[-=]/g) || undefined);
|
|
63627
|
-
return "=" + index;
|
|
63628
|
-
}); }).join(",");
|
|
63633
|
+
// A key that starts with "*" is an indication that we have type references that reference constrained
|
|
63634
|
+
// type parameters. For such keys we also check against the key we would have gotten if all type parameters
|
|
63635
|
+
// were unconstrained.
|
|
63636
|
+
var broadestEquivalentId = id.startsWith("*") ? getRelationKey(source, target, keyIntersectionState, relation, /*ignoreConstraints*/ true) : undefined;
|
|
63629
63637
|
for (var i = 0; i < maybeCount; i++) {
|
|
63630
63638
|
// If source and target are already being compared, consider them related with assumptions
|
|
63631
|
-
if (id === maybeKeys[i] || broadestEquivalentId === maybeKeys[i]) {
|
|
63639
|
+
if (id === maybeKeys[i] || broadestEquivalentId && broadestEquivalentId === maybeKeys[i]) {
|
|
63632
63640
|
return 3 /* Maybe */;
|
|
63633
63641
|
}
|
|
63634
63642
|
}
|
|
@@ -63923,7 +63931,7 @@ var ts;
|
|
|
63923
63931
|
originalErrorInfo = undefined;
|
|
63924
63932
|
}
|
|
63925
63933
|
}
|
|
63926
|
-
else if (isGenericMappedType(target)) {
|
|
63934
|
+
else if (isGenericMappedType(target) && relation !== identityRelation) {
|
|
63927
63935
|
// Check if source type `S` is related to target type `{ [P in Q]: T }` or `{ [P in Q as R]: T}`.
|
|
63928
63936
|
var keysRemapped = !!target.declaration.nameType;
|
|
63929
63937
|
var templateType = getTemplateTypeFromMappedType(target);
|
|
@@ -65135,48 +65143,56 @@ var ts;
|
|
|
65135
65143
|
function isTypeReferenceWithGenericArguments(type) {
|
|
65136
65144
|
return isNonDeferredTypeReference(type) && ts.some(getTypeArguments(type), function (t) { return !!(t.flags & 262144 /* TypeParameter */) || isTypeReferenceWithGenericArguments(t); });
|
|
65137
65145
|
}
|
|
65138
|
-
|
|
65139
|
-
|
|
65140
|
-
|
|
65141
|
-
|
|
65142
|
-
|
|
65143
|
-
|
|
65144
|
-
|
|
65145
|
-
|
|
65146
|
-
|
|
65147
|
-
if (
|
|
65148
|
-
|
|
65149
|
-
|
|
65150
|
-
|
|
65151
|
-
|
|
65146
|
+
function getGenericTypeReferenceRelationKey(source, target, postFix, ignoreConstraints) {
|
|
65147
|
+
var typeParameters = [];
|
|
65148
|
+
var constraintMarker = "";
|
|
65149
|
+
var sourceId = getTypeReferenceId(source, 0);
|
|
65150
|
+
var targetId = getTypeReferenceId(target, 0);
|
|
65151
|
+
return "" + constraintMarker + sourceId + "," + targetId + postFix;
|
|
65152
|
+
// getTypeReferenceId(A<T, number, U>) returns "111=0-12=1"
|
|
65153
|
+
// where A.id=111 and number.id=12
|
|
65154
|
+
function getTypeReferenceId(type, depth) {
|
|
65155
|
+
if (depth === void 0) { depth = 0; }
|
|
65156
|
+
var result = "" + type.target.id;
|
|
65157
|
+
for (var _i = 0, _a = getTypeArguments(type); _i < _a.length; _i++) {
|
|
65158
|
+
var t = _a[_i];
|
|
65159
|
+
if (t.flags & 262144 /* TypeParameter */) {
|
|
65160
|
+
if (ignoreConstraints || isUnconstrainedTypeParameter(t)) {
|
|
65161
|
+
var index = typeParameters.indexOf(t);
|
|
65162
|
+
if (index < 0) {
|
|
65163
|
+
index = typeParameters.length;
|
|
65164
|
+
typeParameters.push(t);
|
|
65165
|
+
}
|
|
65166
|
+
result += "=" + index;
|
|
65167
|
+
continue;
|
|
65168
|
+
}
|
|
65169
|
+
// We mark type references that reference constrained type parameters such that we know to obtain
|
|
65170
|
+
// and look for a "broadest equivalent key" in the cache.
|
|
65171
|
+
constraintMarker = "*";
|
|
65172
|
+
}
|
|
65173
|
+
else if (depth < 4 && isTypeReferenceWithGenericArguments(t)) {
|
|
65174
|
+
result += "<" + getTypeReferenceId(t, depth + 1) + ">";
|
|
65175
|
+
continue;
|
|
65152
65176
|
}
|
|
65153
|
-
result += "=" + index;
|
|
65154
|
-
}
|
|
65155
|
-
else if (depth < 4 && isTypeReferenceWithGenericArguments(t)) {
|
|
65156
|
-
result += "<" + getTypeReferenceId(t, typeParameters, depth + 1) + ">";
|
|
65157
|
-
}
|
|
65158
|
-
else {
|
|
65159
65177
|
result += "-" + t.id;
|
|
65160
65178
|
}
|
|
65179
|
+
return result;
|
|
65161
65180
|
}
|
|
65162
|
-
return result;
|
|
65163
65181
|
}
|
|
65164
65182
|
/**
|
|
65165
65183
|
* To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters.
|
|
65166
65184
|
* For other cases, the types ids are used.
|
|
65167
65185
|
*/
|
|
65168
|
-
function getRelationKey(source, target, intersectionState, relation) {
|
|
65186
|
+
function getRelationKey(source, target, intersectionState, relation, ignoreConstraints) {
|
|
65169
65187
|
if (relation === identityRelation && source.id > target.id) {
|
|
65170
65188
|
var temp = source;
|
|
65171
65189
|
source = target;
|
|
65172
65190
|
target = temp;
|
|
65173
65191
|
}
|
|
65174
65192
|
var postFix = intersectionState ? ":" + intersectionState : "";
|
|
65175
|
-
|
|
65176
|
-
|
|
65177
|
-
|
|
65178
|
-
}
|
|
65179
|
-
return source.id + "," + target.id + postFix;
|
|
65193
|
+
return isTypeReferenceWithGenericArguments(source) && isTypeReferenceWithGenericArguments(target) ?
|
|
65194
|
+
getGenericTypeReferenceRelationKey(source, target, postFix, ignoreConstraints) :
|
|
65195
|
+
source.id + "," + target.id + postFix;
|
|
65180
65196
|
}
|
|
65181
65197
|
// Invoke the callback for each underlying property symbol of the given symbol and return the first
|
|
65182
65198
|
// value that isn't undefined.
|
|
@@ -65224,28 +65240,35 @@ var ts;
|
|
|
65224
65240
|
!hasBaseType(checkClass, getDeclaringClass(p)) : false; }) ? undefined : checkClass;
|
|
65225
65241
|
}
|
|
65226
65242
|
// Return true if the given type is deeply nested. We consider this to be the case when structural type comparisons
|
|
65227
|
-
// for
|
|
65243
|
+
// for maxDepth or more occurrences or instantiations of the type have been recorded on the given stack. It is possible,
|
|
65228
65244
|
// though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely
|
|
65229
|
-
// expanding. Effectively, we will generate a false positive when two types are structurally equal to at least
|
|
65245
|
+
// expanding. Effectively, we will generate a false positive when two types are structurally equal to at least maxDepth
|
|
65230
65246
|
// levels, but unequal at some level beyond that.
|
|
65231
|
-
// In addition, this will also detect when an indexed access has been chained off of
|
|
65232
|
-
// the dual of the structural comparison), and likewise mark the type as deeply nested, potentially adding
|
|
65233
|
-
// for finite but deeply expanding indexed accesses (eg, for `Q[P1][P2][P3][P4][P5]`).
|
|
65234
|
-
// It also detects when a recursive type reference has expanded
|
|
65247
|
+
// In addition, this will also detect when an indexed access has been chained off of maxDepth more times (which is
|
|
65248
|
+
// essentially the dual of the structural comparison), and likewise mark the type as deeply nested, potentially adding
|
|
65249
|
+
// false positives for finite but deeply expanding indexed accesses (eg, for `Q[P1][P2][P3][P4][P5]`).
|
|
65250
|
+
// It also detects when a recursive type reference has expanded maxDepth or more times, e.g. if the true branch of
|
|
65235
65251
|
// `type A<T> = null extends T ? [A<NonNullable<T>>] : [T]`
|
|
65236
|
-
// has expanded into `[A<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>>>>>>]
|
|
65237
|
-
//
|
|
65252
|
+
// has expanded into `[A<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>>>>>>]`. In such cases we need
|
|
65253
|
+
// to terminate the expansion, and we do so here.
|
|
65238
65254
|
function isDeeplyNestedType(type, stack, depth, maxDepth) {
|
|
65239
|
-
if (maxDepth === void 0) { maxDepth =
|
|
65255
|
+
if (maxDepth === void 0) { maxDepth = 3; }
|
|
65240
65256
|
if (depth >= maxDepth) {
|
|
65241
65257
|
var identity_1 = getRecursionIdentity(type);
|
|
65242
65258
|
var count = 0;
|
|
65259
|
+
var lastTypeId = 0;
|
|
65243
65260
|
for (var i = 0; i < depth; i++) {
|
|
65244
|
-
|
|
65245
|
-
|
|
65246
|
-
|
|
65247
|
-
|
|
65261
|
+
var t = stack[i];
|
|
65262
|
+
if (getRecursionIdentity(t) === identity_1) {
|
|
65263
|
+
// We only count occurrences with a higher type id than the previous occurrence, since higher
|
|
65264
|
+
// type ids are an indicator of newer instantiations caused by recursion.
|
|
65265
|
+
if (t.id >= lastTypeId) {
|
|
65266
|
+
count++;
|
|
65267
|
+
if (count >= maxDepth) {
|
|
65268
|
+
return true;
|
|
65269
|
+
}
|
|
65248
65270
|
}
|
|
65271
|
+
lastTypeId = t.id;
|
|
65249
65272
|
}
|
|
65250
65273
|
}
|
|
65251
65274
|
}
|
|
@@ -67350,29 +67373,6 @@ var ts;
|
|
|
67350
67373
|
}
|
|
67351
67374
|
return false;
|
|
67352
67375
|
}
|
|
67353
|
-
function getPropertyAccess(expr) {
|
|
67354
|
-
if (ts.isAccessExpression(expr)) {
|
|
67355
|
-
return expr;
|
|
67356
|
-
}
|
|
67357
|
-
if (ts.isIdentifier(expr)) {
|
|
67358
|
-
var symbol = getResolvedSymbol(expr);
|
|
67359
|
-
if (isConstVariable(symbol)) {
|
|
67360
|
-
var declaration = symbol.valueDeclaration;
|
|
67361
|
-
// Given 'const x = obj.kind', allow 'x' as an alias for 'obj.kind'
|
|
67362
|
-
if (ts.isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && ts.isAccessExpression(declaration.initializer)) {
|
|
67363
|
-
return declaration.initializer;
|
|
67364
|
-
}
|
|
67365
|
-
// Given 'const { kind: x } = obj', allow 'x' as an alias for 'obj.kind'
|
|
67366
|
-
if (ts.isBindingElement(declaration) && !declaration.initializer) {
|
|
67367
|
-
var parent = declaration.parent.parent;
|
|
67368
|
-
if (ts.isVariableDeclaration(parent) && !parent.type && parent.initializer && (ts.isIdentifier(parent.initializer) || ts.isAccessExpression(parent.initializer))) {
|
|
67369
|
-
return declaration;
|
|
67370
|
-
}
|
|
67371
|
-
}
|
|
67372
|
-
}
|
|
67373
|
-
}
|
|
67374
|
-
return undefined;
|
|
67375
|
-
}
|
|
67376
67376
|
function getAccessedPropertyName(access) {
|
|
67377
67377
|
var propertyName;
|
|
67378
67378
|
return access.kind === 205 /* PropertyAccessExpression */ ? access.name.escapedText :
|
|
@@ -68271,20 +68271,21 @@ var ts;
|
|
|
68271
68271
|
}
|
|
68272
68272
|
return false;
|
|
68273
68273
|
}
|
|
68274
|
-
function getFlowTypeOfReference(reference, declaredType, initialType, flowContainer) {
|
|
68274
|
+
function getFlowTypeOfReference(reference, declaredType, initialType, flowContainer, flowNode) {
|
|
68275
68275
|
if (initialType === void 0) { initialType = declaredType; }
|
|
68276
|
+
if (flowNode === void 0) { flowNode = reference.flowNode; }
|
|
68276
68277
|
var key;
|
|
68277
68278
|
var isKeySet = false;
|
|
68278
68279
|
var flowDepth = 0;
|
|
68279
68280
|
if (flowAnalysisDisabled) {
|
|
68280
68281
|
return errorType;
|
|
68281
68282
|
}
|
|
68282
|
-
if (!
|
|
68283
|
+
if (!flowNode) {
|
|
68283
68284
|
return declaredType;
|
|
68284
68285
|
}
|
|
68285
68286
|
flowInvocationCount++;
|
|
68286
68287
|
var sharedFlowStart = sharedFlowCount;
|
|
68287
|
-
var evolvedType = getTypeFromFlowType(getTypeAtFlowNode(
|
|
68288
|
+
var evolvedType = getTypeFromFlowType(getTypeAtFlowNode(flowNode));
|
|
68288
68289
|
sharedFlowCount = sharedFlowStart;
|
|
68289
68290
|
// When the reference is 'x' in an 'x.length', 'x.push(value)', 'x.unshift(value)' or x[n] = value' operation,
|
|
68290
68291
|
// we give type 'any[]' to 'x' instead of using the type determined by control flow analysis such that operations
|
|
@@ -68716,13 +68717,57 @@ var ts;
|
|
|
68716
68717
|
}
|
|
68717
68718
|
return result;
|
|
68718
68719
|
}
|
|
68720
|
+
function getCandidateDiscriminantPropertyAccess(expr) {
|
|
68721
|
+
if (ts.isBindingPattern(reference)) {
|
|
68722
|
+
// When the reference is a binding pattern, we are narrowing a pesudo-reference in getNarrowedTypeOfSymbol.
|
|
68723
|
+
// An identifier for a destructuring variable declared in the same binding pattern is a candidate.
|
|
68724
|
+
if (ts.isIdentifier(expr)) {
|
|
68725
|
+
var symbol = getResolvedSymbol(expr);
|
|
68726
|
+
var declaration = symbol.valueDeclaration;
|
|
68727
|
+
if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && reference === declaration.parent) {
|
|
68728
|
+
return declaration;
|
|
68729
|
+
}
|
|
68730
|
+
}
|
|
68731
|
+
}
|
|
68732
|
+
else if (ts.isAccessExpression(expr)) {
|
|
68733
|
+
// An access expression is a candidate if the reference matches the left hand expression.
|
|
68734
|
+
if (isMatchingReference(reference, expr.expression)) {
|
|
68735
|
+
return expr;
|
|
68736
|
+
}
|
|
68737
|
+
}
|
|
68738
|
+
else if (ts.isIdentifier(expr)) {
|
|
68739
|
+
var symbol = getResolvedSymbol(expr);
|
|
68740
|
+
if (isConstVariable(symbol)) {
|
|
68741
|
+
var declaration = symbol.valueDeclaration;
|
|
68742
|
+
// Given 'const x = obj.kind', allow 'x' as an alias for 'obj.kind'
|
|
68743
|
+
if (ts.isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && ts.isAccessExpression(declaration.initializer) &&
|
|
68744
|
+
isMatchingReference(reference, declaration.initializer.expression)) {
|
|
68745
|
+
return declaration.initializer;
|
|
68746
|
+
}
|
|
68747
|
+
// Given 'const { kind: x } = obj', allow 'x' as an alias for 'obj.kind'
|
|
68748
|
+
if (ts.isBindingElement(declaration) && !declaration.initializer) {
|
|
68749
|
+
var parent = declaration.parent.parent;
|
|
68750
|
+
if (ts.isVariableDeclaration(parent) && !parent.type && parent.initializer && (ts.isIdentifier(parent.initializer) || ts.isAccessExpression(parent.initializer)) &&
|
|
68751
|
+
isMatchingReference(reference, parent.initializer)) {
|
|
68752
|
+
return declaration;
|
|
68753
|
+
}
|
|
68754
|
+
}
|
|
68755
|
+
}
|
|
68756
|
+
}
|
|
68757
|
+
return undefined;
|
|
68758
|
+
}
|
|
68719
68759
|
function getDiscriminantPropertyAccess(expr, computedType) {
|
|
68720
|
-
var access, name;
|
|
68721
68760
|
var type = declaredType.flags & 1048576 /* Union */ ? declaredType : computedType;
|
|
68722
|
-
|
|
68723
|
-
|
|
68724
|
-
|
|
68725
|
-
|
|
68761
|
+
if (type.flags & 1048576 /* Union */) {
|
|
68762
|
+
var access = getCandidateDiscriminantPropertyAccess(expr);
|
|
68763
|
+
if (access) {
|
|
68764
|
+
var name = getAccessedPropertyName(access);
|
|
68765
|
+
if (name && isDiscriminantProperty(type, name)) {
|
|
68766
|
+
return access;
|
|
68767
|
+
}
|
|
68768
|
+
}
|
|
68769
|
+
}
|
|
68770
|
+
return undefined;
|
|
68726
68771
|
}
|
|
68727
68772
|
function narrowTypeByDiscriminant(type, access, narrowType) {
|
|
68728
68773
|
var propName = getAccessedPropertyName(access);
|
|
@@ -69480,6 +69525,49 @@ var ts;
|
|
|
69480
69525
|
}
|
|
69481
69526
|
}
|
|
69482
69527
|
}
|
|
69528
|
+
function getNarrowedTypeOfSymbol(symbol, location) {
|
|
69529
|
+
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69530
|
+
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69531
|
+
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69532
|
+
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69533
|
+
// other binding elements from the same destructuring. Consider:
|
|
69534
|
+
//
|
|
69535
|
+
// type Action =
|
|
69536
|
+
// | { kind: 'A', payload: number }
|
|
69537
|
+
// | { kind: 'B', payload: string };
|
|
69538
|
+
//
|
|
69539
|
+
// function f1({ kind, payload }: Action) {
|
|
69540
|
+
// if (kind === 'A') {
|
|
69541
|
+
// payload.toFixed();
|
|
69542
|
+
// }
|
|
69543
|
+
// if (kind === 'B') {
|
|
69544
|
+
// payload.toUpperCase();
|
|
69545
|
+
// }
|
|
69546
|
+
// }
|
|
69547
|
+
//
|
|
69548
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69549
|
+
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69550
|
+
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69551
|
+
// destructuring from the narrowed parent type.
|
|
69552
|
+
var declaration = symbol.valueDeclaration;
|
|
69553
|
+
if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
|
|
69554
|
+
var parent = declaration.parent.parent;
|
|
69555
|
+
if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
|
|
69556
|
+
var links = getNodeLinks(location);
|
|
69557
|
+
if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
|
|
69558
|
+
links.flags |= 268435456 /* InCheckIdentifier */;
|
|
69559
|
+
var parentType = getTypeForBindingElementParent(parent);
|
|
69560
|
+
links.flags &= ~268435456 /* InCheckIdentifier */;
|
|
69561
|
+
if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
|
|
69562
|
+
var pattern = declaration.parent;
|
|
69563
|
+
var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
|
|
69564
|
+
return getBindingElementTypeFromParentType(declaration, narrowedType);
|
|
69565
|
+
}
|
|
69566
|
+
}
|
|
69567
|
+
}
|
|
69568
|
+
}
|
|
69569
|
+
return getTypeOfSymbol(symbol);
|
|
69570
|
+
}
|
|
69483
69571
|
function checkIdentifier(node, checkMode) {
|
|
69484
69572
|
var symbol = getResolvedSymbol(node);
|
|
69485
69573
|
if (symbol === unknownSymbol) {
|
|
@@ -69553,7 +69641,7 @@ var ts;
|
|
|
69553
69641
|
}
|
|
69554
69642
|
}
|
|
69555
69643
|
checkNestedBlockScopedBinding(node, symbol);
|
|
69556
|
-
var type =
|
|
69644
|
+
var type = getNarrowedTypeOfSymbol(localOrExportSymbol, node);
|
|
69557
69645
|
var assignmentKind = ts.getAssignmentTargetKind(node);
|
|
69558
69646
|
if (assignmentKind) {
|
|
69559
69647
|
if (!(localOrExportSymbol.flags & 3 /* Variable */) &&
|
|
@@ -70596,13 +70684,13 @@ var ts;
|
|
|
70596
70684
|
function isCircularMappedProperty(symbol) {
|
|
70597
70685
|
return !!(ts.getCheckFlags(symbol) & 262144 /* Mapped */ && !symbol.type && findResolutionCycleStartIndex(symbol, 0 /* Type */) >= 0);
|
|
70598
70686
|
}
|
|
70599
|
-
function getTypeOfPropertyOfContextualType(type, name) {
|
|
70687
|
+
function getTypeOfPropertyOfContextualType(type, name, nameType) {
|
|
70600
70688
|
return mapType(type, function (t) {
|
|
70601
70689
|
var _a;
|
|
70602
70690
|
if (isGenericMappedType(t)) {
|
|
70603
70691
|
var constraint = getConstraintTypeFromMappedType(t);
|
|
70604
70692
|
var constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint;
|
|
70605
|
-
var propertyNameType = getStringLiteralType(ts.unescapeLeadingUnderscores(name));
|
|
70693
|
+
var propertyNameType = nameType || getStringLiteralType(ts.unescapeLeadingUnderscores(name));
|
|
70606
70694
|
if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) {
|
|
70607
70695
|
return substituteIndexedMappedType(t, propertyNameType);
|
|
70608
70696
|
}
|
|
@@ -70618,7 +70706,7 @@ var ts;
|
|
|
70618
70706
|
return restType;
|
|
70619
70707
|
}
|
|
70620
70708
|
}
|
|
70621
|
-
return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), getStringLiteralType(ts.unescapeLeadingUnderscores(name)))) === null || _a === void 0 ? void 0 : _a.type;
|
|
70709
|
+
return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(ts.unescapeLeadingUnderscores(name)))) === null || _a === void 0 ? void 0 : _a.type;
|
|
70622
70710
|
}
|
|
70623
70711
|
return undefined;
|
|
70624
70712
|
}, /*noReductions*/ true);
|
|
@@ -70646,7 +70734,8 @@ var ts;
|
|
|
70646
70734
|
// For a (non-symbol) computed property, there is no reason to look up the name
|
|
70647
70735
|
// in the type. It will just be "__computed", which does not appear in any
|
|
70648
70736
|
// SymbolTable.
|
|
70649
|
-
|
|
70737
|
+
var symbol = getSymbolOfNode(element);
|
|
70738
|
+
return getTypeOfPropertyOfContextualType(type, symbol.escapedName, getSymbolLinks(symbol).nameType);
|
|
70650
70739
|
}
|
|
70651
70740
|
if (element.name) {
|
|
70652
70741
|
var nameType_2 = getLiteralTypeFromPropertyName(element.name);
|
|
@@ -82769,8 +82858,11 @@ var ts;
|
|
|
82769
82858
|
function checkAssertClause(declaration) {
|
|
82770
82859
|
var _a;
|
|
82771
82860
|
if (declaration.assertClause) {
|
|
82772
|
-
|
|
82773
|
-
|
|
82861
|
+
var mode = (moduleKind === ts.ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
|
|
82862
|
+
if (mode !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.ESNext) {
|
|
82863
|
+
return grammarErrorOnNode(declaration.assertClause, moduleKind === ts.ModuleKind.NodeNext
|
|
82864
|
+
? ts.Diagnostics.Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls
|
|
82865
|
+
: ts.Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext);
|
|
82774
82866
|
}
|
|
82775
82867
|
if (ts.isImportDeclaration(declaration) ? (_a = declaration.importClause) === null || _a === void 0 ? void 0 : _a.isTypeOnly : declaration.isTypeOnly) {
|
|
82776
82868
|
return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports);
|
|
@@ -86617,12 +86709,12 @@ var ts;
|
|
|
86617
86709
|
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_cannot_have_type_arguments);
|
|
86618
86710
|
}
|
|
86619
86711
|
var nodeArguments = node.arguments;
|
|
86620
|
-
if (moduleKind !== ts.ModuleKind.ESNext) {
|
|
86712
|
+
if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) {
|
|
86621
86713
|
// We are allowed trailing comma after proposal-import-assertions.
|
|
86622
86714
|
checkGrammarForDisallowedTrailingComma(nodeArguments);
|
|
86623
86715
|
if (nodeArguments.length > 1) {
|
|
86624
86716
|
var assertionArgument = nodeArguments[1];
|
|
86625
|
-
return grammarErrorOnNode(assertionArgument, ts.Diagnostics.
|
|
86717
|
+
return grammarErrorOnNode(assertionArgument, ts.Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_or_nodenext);
|
|
86626
86718
|
}
|
|
86627
86719
|
}
|
|
86628
86720
|
if (nodeArguments.length === 0 || nodeArguments.length > 2) {
|