typescript 4.8.0-dev.20220726 → 4.8.0-dev.20220727
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.es2015.proxy.d.ts +91 -2
- package/lib/tsc.js +8 -3
- package/lib/tsserver.js +127 -17
- package/lib/tsserverlibrary.js +127 -17
- package/lib/typescript.js +127 -17
- package/lib/typescriptServices.js +127 -17
- package/lib/typingsInstaller.js +11 -4
- package/package.json +1 -1
|
@@ -19,23 +19,112 @@ and limitations under the License.
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
interface ProxyHandler<T extends object> {
|
|
22
|
+
/**
|
|
23
|
+
* A trap method for a function call.
|
|
24
|
+
* @param target The original callable object which is being proxied.
|
|
25
|
+
*/
|
|
22
26
|
apply?(target: T, thisArg: any, argArray: any[]): any;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A trap for the `new` operator.
|
|
30
|
+
* @param target The original object which is being proxied.
|
|
31
|
+
* @param newTarget The constructor that was originally called.
|
|
32
|
+
*/
|
|
23
33
|
construct?(target: T, argArray: any[], newTarget: Function): object;
|
|
24
|
-
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A trap for `Object.defineProperty()`.
|
|
37
|
+
* @param target The original object which is being proxied.
|
|
38
|
+
* @returns A `Boolean` indicating whether or not the property has been defined.
|
|
39
|
+
*/
|
|
40
|
+
defineProperty?(target: T, property: string | symbol, attributes: PropertyDescriptor): boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A trap for the `delete` operator.
|
|
44
|
+
* @param target The original object which is being proxied.
|
|
45
|
+
* @param p The name or `Symbol` of the property to delete.
|
|
46
|
+
* @returns A `Boolean` indicating whether or not the property was deleted.
|
|
47
|
+
*/
|
|
25
48
|
deleteProperty?(target: T, p: string | symbol): boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A trap for getting a property value.
|
|
52
|
+
* @param target The original object which is being proxied.
|
|
53
|
+
* @param p The name or `Symbol` of the property to get.
|
|
54
|
+
* @param receiver The proxy or an object that inherits from the proxy.
|
|
55
|
+
*/
|
|
26
56
|
get?(target: T, p: string | symbol, receiver: any): any;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A trap for `Object.getOwnPropertyDescriptor()`.
|
|
60
|
+
* @param target The original object which is being proxied.
|
|
61
|
+
* @param p The name of the property whose description should be retrieved.
|
|
62
|
+
*/
|
|
27
63
|
getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A trap for the `[[GetPrototypeOf]]` internal method.
|
|
67
|
+
* @param target The original object which is being proxied.
|
|
68
|
+
*/
|
|
28
69
|
getPrototypeOf?(target: T): object | null;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A trap for the `in` operator.
|
|
73
|
+
* @param target The original object which is being proxied.
|
|
74
|
+
* @param p The name or `Symbol` of the property to check for existence.
|
|
75
|
+
*/
|
|
29
76
|
has?(target: T, p: string | symbol): boolean;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A trap for `Object.isExtensible()`.
|
|
80
|
+
* @param target The original object which is being proxied.
|
|
81
|
+
*/
|
|
30
82
|
isExtensible?(target: T): boolean;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A trap for `Reflect.ownKeys()`.
|
|
86
|
+
* @param target The original object which is being proxied.
|
|
87
|
+
*/
|
|
31
88
|
ownKeys?(target: T): ArrayLike<string | symbol>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A trap for `Object.preventExtensions()`.
|
|
92
|
+
* @param target The original object which is being proxied.
|
|
93
|
+
*/
|
|
32
94
|
preventExtensions?(target: T): boolean;
|
|
33
|
-
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A trap for setting a property value.
|
|
98
|
+
* @param target The original object which is being proxied.
|
|
99
|
+
* @param p The name or `Symbol` of the property to set.
|
|
100
|
+
* @param receiver The object to which the assignment was originally directed.
|
|
101
|
+
* @returns `A `Boolean` indicating whether or not the property was set.
|
|
102
|
+
*/
|
|
103
|
+
set?(target: T, p: string | symbol, newValue: any, receiver: any): boolean;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A trap for `Object.setPrototypeOf()`.
|
|
107
|
+
* @param target The original object which is being proxied.
|
|
108
|
+
* @param newPrototype The object's new prototype or `null`.
|
|
109
|
+
*/
|
|
34
110
|
setPrototypeOf?(target: T, v: object | null): boolean;
|
|
35
111
|
}
|
|
36
112
|
|
|
37
113
|
interface ProxyConstructor {
|
|
114
|
+
/**
|
|
115
|
+
* Creates a revocable Proxy object.
|
|
116
|
+
* @param target A target object to wrap with Proxy.
|
|
117
|
+
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
|
|
118
|
+
*/
|
|
38
119
|
revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the
|
|
123
|
+
* original object, but which may redefine fundamental Object operations like getting, setting, and defining
|
|
124
|
+
* properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs.
|
|
125
|
+
* @param target A target object to wrap with Proxy.
|
|
126
|
+
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
|
|
127
|
+
*/
|
|
39
128
|
new <T extends object>(target: T, handler: ProxyHandler<T>): T;
|
|
40
129
|
}
|
|
41
130
|
declare var Proxy: ProxyConstructor;
|
package/lib/tsc.js
CHANGED
|
@@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
69
69
|
var ts;
|
|
70
70
|
(function (ts) {
|
|
71
71
|
ts.versionMajorMinor = "4.8";
|
|
72
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
72
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220727";
|
|
73
73
|
var NativeCollections;
|
|
74
74
|
(function (NativeCollections) {
|
|
75
75
|
var globals = typeof globalThis !== "undefined" ? globalThis :
|
|
@@ -5731,6 +5731,7 @@ var ts;
|
|
|
5731
5731
|
Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
|
|
5732
5732
|
auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
|
|
5733
5733
|
An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
|
|
5734
|
+
Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
|
|
5734
5735
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
5735
5736
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
5736
5737
|
Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", undefined, true),
|
|
@@ -26880,7 +26881,9 @@ var ts;
|
|
|
26880
26881
|
case 23: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
26881
26882
|
case 13: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
26882
26883
|
case 14: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
26883
|
-
|
|
26884
|
+
case 24: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected);
|
|
26885
|
+
case 25: return ts.Debug.fail("ParsingContext.Count used as a context");
|
|
26886
|
+
default: ts.Debug.assertNever(context);
|
|
26884
26887
|
}
|
|
26885
26888
|
}
|
|
26886
26889
|
function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
|
|
@@ -60178,7 +60181,9 @@ var ts;
|
|
|
60178
60181
|
var narrowedType = mapType(candidate, function (c) {
|
|
60179
60182
|
var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
|
|
60180
60183
|
var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
|
|
60181
|
-
var directlyRelated = mapType(matching || type,
|
|
60184
|
+
var directlyRelated = mapType(matching || type, checkDerived ?
|
|
60185
|
+
function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
|
|
60186
|
+
function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
|
|
60182
60187
|
return directlyRelated.flags & 131072 ?
|
|
60183
60188
|
mapType(type, function (t) { return maybeTypeOfKind(t, 465829888) && isRelated(c, getBaseConstraintOfType(t) || unknownType) ? getIntersectionType([t, c]) : neverType; }) :
|
|
60184
60189
|
directlyRelated;
|
package/lib/tsserver.js
CHANGED
|
@@ -109,7 +109,7 @@ var ts;
|
|
|
109
109
|
// The following is baselined as a literal template type without intervention
|
|
110
110
|
/** The version of the TypeScript compiler release */
|
|
111
111
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
112
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
112
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220727";
|
|
113
113
|
/* @internal */
|
|
114
114
|
var Comparison;
|
|
115
115
|
(function (Comparison) {
|
|
@@ -8577,6 +8577,7 @@ var ts;
|
|
|
8577
8577
|
Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
|
|
8578
8578
|
auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
|
|
8579
8579
|
An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
|
|
8580
|
+
Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
|
|
8580
8581
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
8581
8582
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
8582
8583
|
Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
@@ -33316,7 +33317,9 @@ var ts;
|
|
|
33316
33317
|
case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33317
33318
|
case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33318
33319
|
case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33319
|
-
|
|
33320
|
+
case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
|
|
33321
|
+
case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
|
|
33322
|
+
default: ts.Debug.assertNever(context);
|
|
33320
33323
|
}
|
|
33321
33324
|
}
|
|
33322
33325
|
function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
|
|
@@ -71948,8 +71951,12 @@ var ts;
|
|
|
71948
71951
|
var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
|
|
71949
71952
|
var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
|
|
71950
71953
|
// For each constituent t in the current type, if t and and c are directly related, pick the most
|
|
71951
|
-
// specific of the two.
|
|
71952
|
-
|
|
71954
|
+
// specific of the two. When t and c are related in both directions, we prefer c for type predicates
|
|
71955
|
+
// because that is the asserted type, but t for `instanceof` because generics aren't reflected in
|
|
71956
|
+
// prototype object types.
|
|
71957
|
+
var directlyRelated = mapType(matching || type, checkDerived ?
|
|
71958
|
+
function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
|
|
71959
|
+
function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
|
|
71953
71960
|
// If no constituents are directly related, create intersections for any generic constituents that
|
|
71954
71961
|
// are related by constraint.
|
|
71955
71962
|
return directlyRelated.flags & 131072 /* Never */ ?
|
|
@@ -155389,8 +155396,7 @@ var ts;
|
|
|
155389
155396
|
codefix.eachDiagnostic(context, errorCodes, function (diag) {
|
|
155390
155397
|
var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
|
|
155391
155398
|
if (info) {
|
|
155392
|
-
|
|
155393
|
-
if (ts.addToSeen(seen, id)) {
|
|
155399
|
+
if (ts.addToSeen(seen, ts.getNodeId(info.declaration))) {
|
|
155394
155400
|
return addMissingConstraint(changes, program, preferences, host, diag.file, info);
|
|
155395
155401
|
}
|
|
155396
155402
|
}
|
|
@@ -159358,21 +159364,16 @@ var ts;
|
|
|
159358
159364
|
var names = ts.map(args, function (arg) {
|
|
159359
159365
|
return ts.isIdentifier(arg) ? arg.text : ts.isPropertyAccessExpression(arg) && ts.isIdentifier(arg.name) ? arg.name.text : undefined;
|
|
159360
159366
|
});
|
|
159361
|
-
var
|
|
159362
|
-
|
|
159363
|
-
});
|
|
159367
|
+
var instanceTypes = isJs ? [] : ts.map(args, function (arg) { return checker.getTypeAtLocation(arg); });
|
|
159368
|
+
var _a = getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, /*flags*/ undefined, tracker), argumentTypeNodes = _a.argumentTypeNodes, argumentTypeParameters = _a.argumentTypeParameters;
|
|
159364
159369
|
var modifiers = modifierFlags
|
|
159365
159370
|
? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags))
|
|
159366
159371
|
: undefined;
|
|
159367
159372
|
var asteriskToken = ts.isYieldExpression(parent)
|
|
159368
159373
|
? ts.factory.createToken(41 /* AsteriskToken */)
|
|
159369
159374
|
: undefined;
|
|
159370
|
-
var typeParameters = isJs
|
|
159371
|
-
|
|
159372
|
-
: ts.map(typeArguments, function (_, i) {
|
|
159373
|
-
return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, 84 /* T */ + typeArguments.length - 1 <= 90 /* Z */ ? String.fromCharCode(84 /* T */ + i) : "T" + i);
|
|
159374
|
-
});
|
|
159375
|
-
var parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
|
|
159375
|
+
var typeParameters = isJs ? undefined : createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments);
|
|
159376
|
+
var parameters = createDummyParameters(args.length, names, argumentTypeNodes, /*minArgumentCount*/ undefined, isJs);
|
|
159376
159377
|
var type = isJs || contextualType === undefined
|
|
159377
159378
|
? undefined
|
|
159378
159379
|
: checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
|
|
@@ -159390,6 +159391,23 @@ var ts;
|
|
|
159390
159391
|
}
|
|
159391
159392
|
}
|
|
159392
159393
|
codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
|
|
159394
|
+
function createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments) {
|
|
159395
|
+
var usedNames = new ts.Set(argumentTypeParameters.map(function (pair) { return pair[0]; }));
|
|
159396
|
+
var constraintsByName = new ts.Map(argumentTypeParameters);
|
|
159397
|
+
if (typeArguments) {
|
|
159398
|
+
var typeArgumentsWithNewTypes = typeArguments.filter(function (typeArgument) { return !argumentTypeParameters.some(function (pair) { var _a; return checker.getTypeAtLocation(typeArgument) === ((_a = pair[1]) === null || _a === void 0 ? void 0 : _a.argumentType); }); });
|
|
159399
|
+
var targetSize = usedNames.size + typeArgumentsWithNewTypes.length;
|
|
159400
|
+
for (var i = 0; usedNames.size < targetSize; i += 1) {
|
|
159401
|
+
usedNames.add(createTypeParameterName(i));
|
|
159402
|
+
}
|
|
159403
|
+
}
|
|
159404
|
+
return ts.map(ts.arrayFrom(usedNames.values()), function (usedName) { var _a; return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, usedName, (_a = constraintsByName.get(usedName)) === null || _a === void 0 ? void 0 : _a.constraint); });
|
|
159405
|
+
}
|
|
159406
|
+
function createTypeParameterName(index) {
|
|
159407
|
+
return 84 /* T */ + index <= 90 /* Z */
|
|
159408
|
+
? String.fromCharCode(84 /* T */ + index)
|
|
159409
|
+
: "T" + index;
|
|
159410
|
+
}
|
|
159393
159411
|
function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
|
|
159394
159412
|
var typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
|
|
159395
159413
|
if (typeNode && ts.isImportTypeNode(typeNode)) {
|
|
@@ -159403,15 +159421,107 @@ var ts;
|
|
|
159403
159421
|
return ts.getSynthesizedDeepClone(typeNode);
|
|
159404
159422
|
}
|
|
159405
159423
|
codefix.typeToAutoImportableTypeNode = typeToAutoImportableTypeNode;
|
|
159424
|
+
function typeContainsTypeParameter(type) {
|
|
159425
|
+
if (type.isUnionOrIntersection()) {
|
|
159426
|
+
return type.types.some(typeContainsTypeParameter);
|
|
159427
|
+
}
|
|
159428
|
+
return type.flags & 262144 /* TypeParameter */;
|
|
159429
|
+
}
|
|
159430
|
+
function getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, flags, tracker) {
|
|
159431
|
+
// Types to be used as the types of the parameters in the new function
|
|
159432
|
+
// E.g. from this source:
|
|
159433
|
+
// added("", 0)
|
|
159434
|
+
// The value will look like:
|
|
159435
|
+
// [{ typeName: { text: "string" } }, { typeName: { text: "number" }]
|
|
159436
|
+
// And in the output function will generate:
|
|
159437
|
+
// function added(a: string, b: number) { ... }
|
|
159438
|
+
var argumentTypeNodes = [];
|
|
159439
|
+
// Names of type parameters provided as arguments to the call
|
|
159440
|
+
// E.g. from this source:
|
|
159441
|
+
// added<T, U>(value);
|
|
159442
|
+
// The value will look like:
|
|
159443
|
+
// [
|
|
159444
|
+
// ["T", { argumentType: { typeName: { text: "T" } } } ],
|
|
159445
|
+
// ["U", { argumentType: { typeName: { text: "U" } } } ],
|
|
159446
|
+
// ]
|
|
159447
|
+
// And in the output function will generate:
|
|
159448
|
+
// function added<T, U>() { ... }
|
|
159449
|
+
var argumentTypeParameters = new ts.Map();
|
|
159450
|
+
for (var i = 0; i < instanceTypes.length; i += 1) {
|
|
159451
|
+
var instanceType = instanceTypes[i];
|
|
159452
|
+
// If the instance type contains a deep reference to an existing type parameter,
|
|
159453
|
+
// instead of copying the full union or intersection, create a new type parameter
|
|
159454
|
+
// E.g. from this source:
|
|
159455
|
+
// function existing<T, U>(value: T | U & string) {
|
|
159456
|
+
// added/*1*/(value);
|
|
159457
|
+
// We don't want to output this:
|
|
159458
|
+
// function added<T>(value: T | U & string) { ... }
|
|
159459
|
+
// We instead want to output:
|
|
159460
|
+
// function added<T>(value: T) { ... }
|
|
159461
|
+
if (instanceType.isUnionOrIntersection() && instanceType.types.some(typeContainsTypeParameter)) {
|
|
159462
|
+
var synthesizedTypeParameterName = createTypeParameterName(i);
|
|
159463
|
+
argumentTypeNodes.push(ts.factory.createTypeReferenceNode(synthesizedTypeParameterName));
|
|
159464
|
+
argumentTypeParameters.set(synthesizedTypeParameterName, undefined);
|
|
159465
|
+
continue;
|
|
159466
|
+
}
|
|
159467
|
+
// Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
|
|
159468
|
+
var widenedInstanceType = checker.getBaseTypeOfLiteralType(instanceType);
|
|
159469
|
+
var argumentTypeNode = typeToAutoImportableTypeNode(checker, importAdder, widenedInstanceType, contextNode, scriptTarget, flags, tracker);
|
|
159470
|
+
if (!argumentTypeNode) {
|
|
159471
|
+
continue;
|
|
159472
|
+
}
|
|
159473
|
+
argumentTypeNodes.push(argumentTypeNode);
|
|
159474
|
+
var argumentTypeParameter = getFirstTypeParameterName(instanceType);
|
|
159475
|
+
// If the instance type is a type parameter with a constraint (other than an anonymous object),
|
|
159476
|
+
// remember that constraint for when we create the new type parameter
|
|
159477
|
+
// E.g. from this source:
|
|
159478
|
+
// function existing<T extends string>(value: T) {
|
|
159479
|
+
// added/*1*/(value);
|
|
159480
|
+
// We don't want to output this:
|
|
159481
|
+
// function added<T>(value: T) { ... }
|
|
159482
|
+
// We instead want to output:
|
|
159483
|
+
// function added<T extends string>(value: T) { ... }
|
|
159484
|
+
var instanceTypeConstraint = instanceType.isTypeParameter() && instanceType.constraint && !isAnonymousObjectConstraintType(instanceType.constraint)
|
|
159485
|
+
? typeToAutoImportableTypeNode(checker, importAdder, instanceType.constraint, contextNode, scriptTarget, flags, tracker)
|
|
159486
|
+
: undefined;
|
|
159487
|
+
if (argumentTypeParameter) {
|
|
159488
|
+
argumentTypeParameters.set(argumentTypeParameter, { argumentType: instanceType, constraint: instanceTypeConstraint });
|
|
159489
|
+
}
|
|
159490
|
+
}
|
|
159491
|
+
return { argumentTypeNodes: argumentTypeNodes, argumentTypeParameters: ts.arrayFrom(argumentTypeParameters.entries()) };
|
|
159492
|
+
}
|
|
159493
|
+
codefix.getArgumentTypesAndTypeParameters = getArgumentTypesAndTypeParameters;
|
|
159494
|
+
function isAnonymousObjectConstraintType(type) {
|
|
159495
|
+
return (type.flags & 524288 /* Object */) && type.objectFlags === 16 /* Anonymous */;
|
|
159496
|
+
}
|
|
159497
|
+
function getFirstTypeParameterName(type) {
|
|
159498
|
+
var _a;
|
|
159499
|
+
if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
|
|
159500
|
+
for (var _i = 0, _b = type.types; _i < _b.length; _i++) {
|
|
159501
|
+
var subType = _b[_i];
|
|
159502
|
+
var subTypeName = getFirstTypeParameterName(subType);
|
|
159503
|
+
if (subTypeName) {
|
|
159504
|
+
return subTypeName;
|
|
159505
|
+
}
|
|
159506
|
+
}
|
|
159507
|
+
}
|
|
159508
|
+
return type.flags & 262144 /* TypeParameter */
|
|
159509
|
+
? (_a = type.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName()
|
|
159510
|
+
: undefined;
|
|
159511
|
+
}
|
|
159406
159512
|
function createDummyParameters(argCount, names, types, minArgumentCount, inJs) {
|
|
159407
159513
|
var parameters = [];
|
|
159514
|
+
var parameterNameCounts = new ts.Map();
|
|
159408
159515
|
for (var i = 0; i < argCount; i++) {
|
|
159516
|
+
var parameterName = (names === null || names === void 0 ? void 0 : names[i]) || "arg" + i;
|
|
159517
|
+
var parameterNameCount = parameterNameCounts.get(parameterName);
|
|
159518
|
+
parameterNameCounts.set(parameterName, (parameterNameCount || 0) + 1);
|
|
159409
159519
|
var newParameter = ts.factory.createParameterDeclaration(
|
|
159410
159520
|
/*modifiers*/ undefined,
|
|
159411
159521
|
/*dotDotDotToken*/ undefined,
|
|
159412
|
-
/*name*/
|
|
159522
|
+
/*name*/ parameterName + (parameterNameCount || ""),
|
|
159413
159523
|
/*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
|
|
159414
|
-
/*type*/ inJs ? undefined : types
|
|
159524
|
+
/*type*/ inJs ? undefined : (types === null || types === void 0 ? void 0 : types[i]) || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
|
|
159415
159525
|
/*initializer*/ undefined);
|
|
159416
159526
|
parameters.push(newParameter);
|
|
159417
159527
|
}
|
package/lib/tsserverlibrary.js
CHANGED
|
@@ -303,7 +303,7 @@ var ts;
|
|
|
303
303
|
// The following is baselined as a literal template type without intervention
|
|
304
304
|
/** The version of the TypeScript compiler release */
|
|
305
305
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
306
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
306
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220727";
|
|
307
307
|
/* @internal */
|
|
308
308
|
var Comparison;
|
|
309
309
|
(function (Comparison) {
|
|
@@ -8771,6 +8771,7 @@ var ts;
|
|
|
8771
8771
|
Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
|
|
8772
8772
|
auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
|
|
8773
8773
|
An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
|
|
8774
|
+
Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
|
|
8774
8775
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
8775
8776
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
8776
8777
|
Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
@@ -33510,7 +33511,9 @@ var ts;
|
|
|
33510
33511
|
case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33511
33512
|
case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33512
33513
|
case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33513
|
-
|
|
33514
|
+
case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
|
|
33515
|
+
case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
|
|
33516
|
+
default: ts.Debug.assertNever(context);
|
|
33514
33517
|
}
|
|
33515
33518
|
}
|
|
33516
33519
|
function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
|
|
@@ -72142,8 +72145,12 @@ var ts;
|
|
|
72142
72145
|
var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
|
|
72143
72146
|
var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
|
|
72144
72147
|
// For each constituent t in the current type, if t and and c are directly related, pick the most
|
|
72145
|
-
// specific of the two.
|
|
72146
|
-
|
|
72148
|
+
// specific of the two. When t and c are related in both directions, we prefer c for type predicates
|
|
72149
|
+
// because that is the asserted type, but t for `instanceof` because generics aren't reflected in
|
|
72150
|
+
// prototype object types.
|
|
72151
|
+
var directlyRelated = mapType(matching || type, checkDerived ?
|
|
72152
|
+
function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
|
|
72153
|
+
function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
|
|
72147
72154
|
// If no constituents are directly related, create intersections for any generic constituents that
|
|
72148
72155
|
// are related by constraint.
|
|
72149
72156
|
return directlyRelated.flags & 131072 /* Never */ ?
|
|
@@ -156002,8 +156009,7 @@ var ts;
|
|
|
156002
156009
|
codefix.eachDiagnostic(context, errorCodes, function (diag) {
|
|
156003
156010
|
var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
|
|
156004
156011
|
if (info) {
|
|
156005
|
-
|
|
156006
|
-
if (ts.addToSeen(seen, id)) {
|
|
156012
|
+
if (ts.addToSeen(seen, ts.getNodeId(info.declaration))) {
|
|
156007
156013
|
return addMissingConstraint(changes, program, preferences, host, diag.file, info);
|
|
156008
156014
|
}
|
|
156009
156015
|
}
|
|
@@ -159971,21 +159977,16 @@ var ts;
|
|
|
159971
159977
|
var names = ts.map(args, function (arg) {
|
|
159972
159978
|
return ts.isIdentifier(arg) ? arg.text : ts.isPropertyAccessExpression(arg) && ts.isIdentifier(arg.name) ? arg.name.text : undefined;
|
|
159973
159979
|
});
|
|
159974
|
-
var
|
|
159975
|
-
|
|
159976
|
-
});
|
|
159980
|
+
var instanceTypes = isJs ? [] : ts.map(args, function (arg) { return checker.getTypeAtLocation(arg); });
|
|
159981
|
+
var _a = getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, /*flags*/ undefined, tracker), argumentTypeNodes = _a.argumentTypeNodes, argumentTypeParameters = _a.argumentTypeParameters;
|
|
159977
159982
|
var modifiers = modifierFlags
|
|
159978
159983
|
? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags))
|
|
159979
159984
|
: undefined;
|
|
159980
159985
|
var asteriskToken = ts.isYieldExpression(parent)
|
|
159981
159986
|
? ts.factory.createToken(41 /* AsteriskToken */)
|
|
159982
159987
|
: undefined;
|
|
159983
|
-
var typeParameters = isJs
|
|
159984
|
-
|
|
159985
|
-
: ts.map(typeArguments, function (_, i) {
|
|
159986
|
-
return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, 84 /* T */ + typeArguments.length - 1 <= 90 /* Z */ ? String.fromCharCode(84 /* T */ + i) : "T" + i);
|
|
159987
|
-
});
|
|
159988
|
-
var parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
|
|
159988
|
+
var typeParameters = isJs ? undefined : createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments);
|
|
159989
|
+
var parameters = createDummyParameters(args.length, names, argumentTypeNodes, /*minArgumentCount*/ undefined, isJs);
|
|
159989
159990
|
var type = isJs || contextualType === undefined
|
|
159990
159991
|
? undefined
|
|
159991
159992
|
: checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
|
|
@@ -160003,6 +160004,23 @@ var ts;
|
|
|
160003
160004
|
}
|
|
160004
160005
|
}
|
|
160005
160006
|
codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
|
|
160007
|
+
function createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments) {
|
|
160008
|
+
var usedNames = new ts.Set(argumentTypeParameters.map(function (pair) { return pair[0]; }));
|
|
160009
|
+
var constraintsByName = new ts.Map(argumentTypeParameters);
|
|
160010
|
+
if (typeArguments) {
|
|
160011
|
+
var typeArgumentsWithNewTypes = typeArguments.filter(function (typeArgument) { return !argumentTypeParameters.some(function (pair) { var _a; return checker.getTypeAtLocation(typeArgument) === ((_a = pair[1]) === null || _a === void 0 ? void 0 : _a.argumentType); }); });
|
|
160012
|
+
var targetSize = usedNames.size + typeArgumentsWithNewTypes.length;
|
|
160013
|
+
for (var i = 0; usedNames.size < targetSize; i += 1) {
|
|
160014
|
+
usedNames.add(createTypeParameterName(i));
|
|
160015
|
+
}
|
|
160016
|
+
}
|
|
160017
|
+
return ts.map(ts.arrayFrom(usedNames.values()), function (usedName) { var _a; return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, usedName, (_a = constraintsByName.get(usedName)) === null || _a === void 0 ? void 0 : _a.constraint); });
|
|
160018
|
+
}
|
|
160019
|
+
function createTypeParameterName(index) {
|
|
160020
|
+
return 84 /* T */ + index <= 90 /* Z */
|
|
160021
|
+
? String.fromCharCode(84 /* T */ + index)
|
|
160022
|
+
: "T" + index;
|
|
160023
|
+
}
|
|
160006
160024
|
function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
|
|
160007
160025
|
var typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
|
|
160008
160026
|
if (typeNode && ts.isImportTypeNode(typeNode)) {
|
|
@@ -160016,15 +160034,107 @@ var ts;
|
|
|
160016
160034
|
return ts.getSynthesizedDeepClone(typeNode);
|
|
160017
160035
|
}
|
|
160018
160036
|
codefix.typeToAutoImportableTypeNode = typeToAutoImportableTypeNode;
|
|
160037
|
+
function typeContainsTypeParameter(type) {
|
|
160038
|
+
if (type.isUnionOrIntersection()) {
|
|
160039
|
+
return type.types.some(typeContainsTypeParameter);
|
|
160040
|
+
}
|
|
160041
|
+
return type.flags & 262144 /* TypeParameter */;
|
|
160042
|
+
}
|
|
160043
|
+
function getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, flags, tracker) {
|
|
160044
|
+
// Types to be used as the types of the parameters in the new function
|
|
160045
|
+
// E.g. from this source:
|
|
160046
|
+
// added("", 0)
|
|
160047
|
+
// The value will look like:
|
|
160048
|
+
// [{ typeName: { text: "string" } }, { typeName: { text: "number" }]
|
|
160049
|
+
// And in the output function will generate:
|
|
160050
|
+
// function added(a: string, b: number) { ... }
|
|
160051
|
+
var argumentTypeNodes = [];
|
|
160052
|
+
// Names of type parameters provided as arguments to the call
|
|
160053
|
+
// E.g. from this source:
|
|
160054
|
+
// added<T, U>(value);
|
|
160055
|
+
// The value will look like:
|
|
160056
|
+
// [
|
|
160057
|
+
// ["T", { argumentType: { typeName: { text: "T" } } } ],
|
|
160058
|
+
// ["U", { argumentType: { typeName: { text: "U" } } } ],
|
|
160059
|
+
// ]
|
|
160060
|
+
// And in the output function will generate:
|
|
160061
|
+
// function added<T, U>() { ... }
|
|
160062
|
+
var argumentTypeParameters = new ts.Map();
|
|
160063
|
+
for (var i = 0; i < instanceTypes.length; i += 1) {
|
|
160064
|
+
var instanceType = instanceTypes[i];
|
|
160065
|
+
// If the instance type contains a deep reference to an existing type parameter,
|
|
160066
|
+
// instead of copying the full union or intersection, create a new type parameter
|
|
160067
|
+
// E.g. from this source:
|
|
160068
|
+
// function existing<T, U>(value: T | U & string) {
|
|
160069
|
+
// added/*1*/(value);
|
|
160070
|
+
// We don't want to output this:
|
|
160071
|
+
// function added<T>(value: T | U & string) { ... }
|
|
160072
|
+
// We instead want to output:
|
|
160073
|
+
// function added<T>(value: T) { ... }
|
|
160074
|
+
if (instanceType.isUnionOrIntersection() && instanceType.types.some(typeContainsTypeParameter)) {
|
|
160075
|
+
var synthesizedTypeParameterName = createTypeParameterName(i);
|
|
160076
|
+
argumentTypeNodes.push(ts.factory.createTypeReferenceNode(synthesizedTypeParameterName));
|
|
160077
|
+
argumentTypeParameters.set(synthesizedTypeParameterName, undefined);
|
|
160078
|
+
continue;
|
|
160079
|
+
}
|
|
160080
|
+
// Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
|
|
160081
|
+
var widenedInstanceType = checker.getBaseTypeOfLiteralType(instanceType);
|
|
160082
|
+
var argumentTypeNode = typeToAutoImportableTypeNode(checker, importAdder, widenedInstanceType, contextNode, scriptTarget, flags, tracker);
|
|
160083
|
+
if (!argumentTypeNode) {
|
|
160084
|
+
continue;
|
|
160085
|
+
}
|
|
160086
|
+
argumentTypeNodes.push(argumentTypeNode);
|
|
160087
|
+
var argumentTypeParameter = getFirstTypeParameterName(instanceType);
|
|
160088
|
+
// If the instance type is a type parameter with a constraint (other than an anonymous object),
|
|
160089
|
+
// remember that constraint for when we create the new type parameter
|
|
160090
|
+
// E.g. from this source:
|
|
160091
|
+
// function existing<T extends string>(value: T) {
|
|
160092
|
+
// added/*1*/(value);
|
|
160093
|
+
// We don't want to output this:
|
|
160094
|
+
// function added<T>(value: T) { ... }
|
|
160095
|
+
// We instead want to output:
|
|
160096
|
+
// function added<T extends string>(value: T) { ... }
|
|
160097
|
+
var instanceTypeConstraint = instanceType.isTypeParameter() && instanceType.constraint && !isAnonymousObjectConstraintType(instanceType.constraint)
|
|
160098
|
+
? typeToAutoImportableTypeNode(checker, importAdder, instanceType.constraint, contextNode, scriptTarget, flags, tracker)
|
|
160099
|
+
: undefined;
|
|
160100
|
+
if (argumentTypeParameter) {
|
|
160101
|
+
argumentTypeParameters.set(argumentTypeParameter, { argumentType: instanceType, constraint: instanceTypeConstraint });
|
|
160102
|
+
}
|
|
160103
|
+
}
|
|
160104
|
+
return { argumentTypeNodes: argumentTypeNodes, argumentTypeParameters: ts.arrayFrom(argumentTypeParameters.entries()) };
|
|
160105
|
+
}
|
|
160106
|
+
codefix.getArgumentTypesAndTypeParameters = getArgumentTypesAndTypeParameters;
|
|
160107
|
+
function isAnonymousObjectConstraintType(type) {
|
|
160108
|
+
return (type.flags & 524288 /* Object */) && type.objectFlags === 16 /* Anonymous */;
|
|
160109
|
+
}
|
|
160110
|
+
function getFirstTypeParameterName(type) {
|
|
160111
|
+
var _a;
|
|
160112
|
+
if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
|
|
160113
|
+
for (var _i = 0, _b = type.types; _i < _b.length; _i++) {
|
|
160114
|
+
var subType = _b[_i];
|
|
160115
|
+
var subTypeName = getFirstTypeParameterName(subType);
|
|
160116
|
+
if (subTypeName) {
|
|
160117
|
+
return subTypeName;
|
|
160118
|
+
}
|
|
160119
|
+
}
|
|
160120
|
+
}
|
|
160121
|
+
return type.flags & 262144 /* TypeParameter */
|
|
160122
|
+
? (_a = type.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName()
|
|
160123
|
+
: undefined;
|
|
160124
|
+
}
|
|
160019
160125
|
function createDummyParameters(argCount, names, types, minArgumentCount, inJs) {
|
|
160020
160126
|
var parameters = [];
|
|
160127
|
+
var parameterNameCounts = new ts.Map();
|
|
160021
160128
|
for (var i = 0; i < argCount; i++) {
|
|
160129
|
+
var parameterName = (names === null || names === void 0 ? void 0 : names[i]) || "arg" + i;
|
|
160130
|
+
var parameterNameCount = parameterNameCounts.get(parameterName);
|
|
160131
|
+
parameterNameCounts.set(parameterName, (parameterNameCount || 0) + 1);
|
|
160022
160132
|
var newParameter = ts.factory.createParameterDeclaration(
|
|
160023
160133
|
/*modifiers*/ undefined,
|
|
160024
160134
|
/*dotDotDotToken*/ undefined,
|
|
160025
|
-
/*name*/
|
|
160135
|
+
/*name*/ parameterName + (parameterNameCount || ""),
|
|
160026
160136
|
/*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
|
|
160027
|
-
/*type*/ inJs ? undefined : types
|
|
160137
|
+
/*type*/ inJs ? undefined : (types === null || types === void 0 ? void 0 : types[i]) || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
|
|
160028
160138
|
/*initializer*/ undefined);
|
|
160029
160139
|
parameters.push(newParameter);
|
|
160030
160140
|
}
|
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.20220727";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -8762,6 +8762,7 @@ var ts;
|
|
|
8762
8762
|
Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
|
|
8763
8763
|
auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
|
|
8764
8764
|
An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
|
|
8765
|
+
Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
|
|
8765
8766
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
8766
8767
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
8767
8768
|
Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
@@ -33501,7 +33502,9 @@ var ts;
|
|
|
33501
33502
|
case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33502
33503
|
case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33503
33504
|
case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33504
|
-
|
|
33505
|
+
case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
|
|
33506
|
+
case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
|
|
33507
|
+
default: ts.Debug.assertNever(context);
|
|
33505
33508
|
}
|
|
33506
33509
|
}
|
|
33507
33510
|
function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
|
|
@@ -72133,8 +72136,12 @@ var ts;
|
|
|
72133
72136
|
var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
|
|
72134
72137
|
var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
|
|
72135
72138
|
// For each constituent t in the current type, if t and and c are directly related, pick the most
|
|
72136
|
-
// specific of the two.
|
|
72137
|
-
|
|
72139
|
+
// specific of the two. When t and c are related in both directions, we prefer c for type predicates
|
|
72140
|
+
// because that is the asserted type, but t for `instanceof` because generics aren't reflected in
|
|
72141
|
+
// prototype object types.
|
|
72142
|
+
var directlyRelated = mapType(matching || type, checkDerived ?
|
|
72143
|
+
function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
|
|
72144
|
+
function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
|
|
72138
72145
|
// If no constituents are directly related, create intersections for any generic constituents that
|
|
72139
72146
|
// are related by constraint.
|
|
72140
72147
|
return directlyRelated.flags & 131072 /* Never */ ?
|
|
@@ -155993,8 +156000,7 @@ var ts;
|
|
|
155993
156000
|
codefix.eachDiagnostic(context, errorCodes, function (diag) {
|
|
155994
156001
|
var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
|
|
155995
156002
|
if (info) {
|
|
155996
|
-
|
|
155997
|
-
if (ts.addToSeen(seen, id)) {
|
|
156003
|
+
if (ts.addToSeen(seen, ts.getNodeId(info.declaration))) {
|
|
155998
156004
|
return addMissingConstraint(changes, program, preferences, host, diag.file, info);
|
|
155999
156005
|
}
|
|
156000
156006
|
}
|
|
@@ -159962,21 +159968,16 @@ var ts;
|
|
|
159962
159968
|
var names = ts.map(args, function (arg) {
|
|
159963
159969
|
return ts.isIdentifier(arg) ? arg.text : ts.isPropertyAccessExpression(arg) && ts.isIdentifier(arg.name) ? arg.name.text : undefined;
|
|
159964
159970
|
});
|
|
159965
|
-
var
|
|
159966
|
-
|
|
159967
|
-
});
|
|
159971
|
+
var instanceTypes = isJs ? [] : ts.map(args, function (arg) { return checker.getTypeAtLocation(arg); });
|
|
159972
|
+
var _a = getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, /*flags*/ undefined, tracker), argumentTypeNodes = _a.argumentTypeNodes, argumentTypeParameters = _a.argumentTypeParameters;
|
|
159968
159973
|
var modifiers = modifierFlags
|
|
159969
159974
|
? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags))
|
|
159970
159975
|
: undefined;
|
|
159971
159976
|
var asteriskToken = ts.isYieldExpression(parent)
|
|
159972
159977
|
? ts.factory.createToken(41 /* AsteriskToken */)
|
|
159973
159978
|
: undefined;
|
|
159974
|
-
var typeParameters = isJs
|
|
159975
|
-
|
|
159976
|
-
: ts.map(typeArguments, function (_, i) {
|
|
159977
|
-
return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, 84 /* T */ + typeArguments.length - 1 <= 90 /* Z */ ? String.fromCharCode(84 /* T */ + i) : "T" + i);
|
|
159978
|
-
});
|
|
159979
|
-
var parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
|
|
159979
|
+
var typeParameters = isJs ? undefined : createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments);
|
|
159980
|
+
var parameters = createDummyParameters(args.length, names, argumentTypeNodes, /*minArgumentCount*/ undefined, isJs);
|
|
159980
159981
|
var type = isJs || contextualType === undefined
|
|
159981
159982
|
? undefined
|
|
159982
159983
|
: checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
|
|
@@ -159994,6 +159995,23 @@ var ts;
|
|
|
159994
159995
|
}
|
|
159995
159996
|
}
|
|
159996
159997
|
codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
|
|
159998
|
+
function createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments) {
|
|
159999
|
+
var usedNames = new ts.Set(argumentTypeParameters.map(function (pair) { return pair[0]; }));
|
|
160000
|
+
var constraintsByName = new ts.Map(argumentTypeParameters);
|
|
160001
|
+
if (typeArguments) {
|
|
160002
|
+
var typeArgumentsWithNewTypes = typeArguments.filter(function (typeArgument) { return !argumentTypeParameters.some(function (pair) { var _a; return checker.getTypeAtLocation(typeArgument) === ((_a = pair[1]) === null || _a === void 0 ? void 0 : _a.argumentType); }); });
|
|
160003
|
+
var targetSize = usedNames.size + typeArgumentsWithNewTypes.length;
|
|
160004
|
+
for (var i = 0; usedNames.size < targetSize; i += 1) {
|
|
160005
|
+
usedNames.add(createTypeParameterName(i));
|
|
160006
|
+
}
|
|
160007
|
+
}
|
|
160008
|
+
return ts.map(ts.arrayFrom(usedNames.values()), function (usedName) { var _a; return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, usedName, (_a = constraintsByName.get(usedName)) === null || _a === void 0 ? void 0 : _a.constraint); });
|
|
160009
|
+
}
|
|
160010
|
+
function createTypeParameterName(index) {
|
|
160011
|
+
return 84 /* T */ + index <= 90 /* Z */
|
|
160012
|
+
? String.fromCharCode(84 /* T */ + index)
|
|
160013
|
+
: "T" + index;
|
|
160014
|
+
}
|
|
159997
160015
|
function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
|
|
159998
160016
|
var typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
|
|
159999
160017
|
if (typeNode && ts.isImportTypeNode(typeNode)) {
|
|
@@ -160007,15 +160025,107 @@ var ts;
|
|
|
160007
160025
|
return ts.getSynthesizedDeepClone(typeNode);
|
|
160008
160026
|
}
|
|
160009
160027
|
codefix.typeToAutoImportableTypeNode = typeToAutoImportableTypeNode;
|
|
160028
|
+
function typeContainsTypeParameter(type) {
|
|
160029
|
+
if (type.isUnionOrIntersection()) {
|
|
160030
|
+
return type.types.some(typeContainsTypeParameter);
|
|
160031
|
+
}
|
|
160032
|
+
return type.flags & 262144 /* TypeParameter */;
|
|
160033
|
+
}
|
|
160034
|
+
function getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, flags, tracker) {
|
|
160035
|
+
// Types to be used as the types of the parameters in the new function
|
|
160036
|
+
// E.g. from this source:
|
|
160037
|
+
// added("", 0)
|
|
160038
|
+
// The value will look like:
|
|
160039
|
+
// [{ typeName: { text: "string" } }, { typeName: { text: "number" }]
|
|
160040
|
+
// And in the output function will generate:
|
|
160041
|
+
// function added(a: string, b: number) { ... }
|
|
160042
|
+
var argumentTypeNodes = [];
|
|
160043
|
+
// Names of type parameters provided as arguments to the call
|
|
160044
|
+
// E.g. from this source:
|
|
160045
|
+
// added<T, U>(value);
|
|
160046
|
+
// The value will look like:
|
|
160047
|
+
// [
|
|
160048
|
+
// ["T", { argumentType: { typeName: { text: "T" } } } ],
|
|
160049
|
+
// ["U", { argumentType: { typeName: { text: "U" } } } ],
|
|
160050
|
+
// ]
|
|
160051
|
+
// And in the output function will generate:
|
|
160052
|
+
// function added<T, U>() { ... }
|
|
160053
|
+
var argumentTypeParameters = new ts.Map();
|
|
160054
|
+
for (var i = 0; i < instanceTypes.length; i += 1) {
|
|
160055
|
+
var instanceType = instanceTypes[i];
|
|
160056
|
+
// If the instance type contains a deep reference to an existing type parameter,
|
|
160057
|
+
// instead of copying the full union or intersection, create a new type parameter
|
|
160058
|
+
// E.g. from this source:
|
|
160059
|
+
// function existing<T, U>(value: T | U & string) {
|
|
160060
|
+
// added/*1*/(value);
|
|
160061
|
+
// We don't want to output this:
|
|
160062
|
+
// function added<T>(value: T | U & string) { ... }
|
|
160063
|
+
// We instead want to output:
|
|
160064
|
+
// function added<T>(value: T) { ... }
|
|
160065
|
+
if (instanceType.isUnionOrIntersection() && instanceType.types.some(typeContainsTypeParameter)) {
|
|
160066
|
+
var synthesizedTypeParameterName = createTypeParameterName(i);
|
|
160067
|
+
argumentTypeNodes.push(ts.factory.createTypeReferenceNode(synthesizedTypeParameterName));
|
|
160068
|
+
argumentTypeParameters.set(synthesizedTypeParameterName, undefined);
|
|
160069
|
+
continue;
|
|
160070
|
+
}
|
|
160071
|
+
// Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
|
|
160072
|
+
var widenedInstanceType = checker.getBaseTypeOfLiteralType(instanceType);
|
|
160073
|
+
var argumentTypeNode = typeToAutoImportableTypeNode(checker, importAdder, widenedInstanceType, contextNode, scriptTarget, flags, tracker);
|
|
160074
|
+
if (!argumentTypeNode) {
|
|
160075
|
+
continue;
|
|
160076
|
+
}
|
|
160077
|
+
argumentTypeNodes.push(argumentTypeNode);
|
|
160078
|
+
var argumentTypeParameter = getFirstTypeParameterName(instanceType);
|
|
160079
|
+
// If the instance type is a type parameter with a constraint (other than an anonymous object),
|
|
160080
|
+
// remember that constraint for when we create the new type parameter
|
|
160081
|
+
// E.g. from this source:
|
|
160082
|
+
// function existing<T extends string>(value: T) {
|
|
160083
|
+
// added/*1*/(value);
|
|
160084
|
+
// We don't want to output this:
|
|
160085
|
+
// function added<T>(value: T) { ... }
|
|
160086
|
+
// We instead want to output:
|
|
160087
|
+
// function added<T extends string>(value: T) { ... }
|
|
160088
|
+
var instanceTypeConstraint = instanceType.isTypeParameter() && instanceType.constraint && !isAnonymousObjectConstraintType(instanceType.constraint)
|
|
160089
|
+
? typeToAutoImportableTypeNode(checker, importAdder, instanceType.constraint, contextNode, scriptTarget, flags, tracker)
|
|
160090
|
+
: undefined;
|
|
160091
|
+
if (argumentTypeParameter) {
|
|
160092
|
+
argumentTypeParameters.set(argumentTypeParameter, { argumentType: instanceType, constraint: instanceTypeConstraint });
|
|
160093
|
+
}
|
|
160094
|
+
}
|
|
160095
|
+
return { argumentTypeNodes: argumentTypeNodes, argumentTypeParameters: ts.arrayFrom(argumentTypeParameters.entries()) };
|
|
160096
|
+
}
|
|
160097
|
+
codefix.getArgumentTypesAndTypeParameters = getArgumentTypesAndTypeParameters;
|
|
160098
|
+
function isAnonymousObjectConstraintType(type) {
|
|
160099
|
+
return (type.flags & 524288 /* Object */) && type.objectFlags === 16 /* Anonymous */;
|
|
160100
|
+
}
|
|
160101
|
+
function getFirstTypeParameterName(type) {
|
|
160102
|
+
var _a;
|
|
160103
|
+
if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
|
|
160104
|
+
for (var _i = 0, _b = type.types; _i < _b.length; _i++) {
|
|
160105
|
+
var subType = _b[_i];
|
|
160106
|
+
var subTypeName = getFirstTypeParameterName(subType);
|
|
160107
|
+
if (subTypeName) {
|
|
160108
|
+
return subTypeName;
|
|
160109
|
+
}
|
|
160110
|
+
}
|
|
160111
|
+
}
|
|
160112
|
+
return type.flags & 262144 /* TypeParameter */
|
|
160113
|
+
? (_a = type.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName()
|
|
160114
|
+
: undefined;
|
|
160115
|
+
}
|
|
160010
160116
|
function createDummyParameters(argCount, names, types, minArgumentCount, inJs) {
|
|
160011
160117
|
var parameters = [];
|
|
160118
|
+
var parameterNameCounts = new ts.Map();
|
|
160012
160119
|
for (var i = 0; i < argCount; i++) {
|
|
160120
|
+
var parameterName = (names === null || names === void 0 ? void 0 : names[i]) || "arg" + i;
|
|
160121
|
+
var parameterNameCount = parameterNameCounts.get(parameterName);
|
|
160122
|
+
parameterNameCounts.set(parameterName, (parameterNameCount || 0) + 1);
|
|
160013
160123
|
var newParameter = ts.factory.createParameterDeclaration(
|
|
160014
160124
|
/*modifiers*/ undefined,
|
|
160015
160125
|
/*dotDotDotToken*/ undefined,
|
|
160016
|
-
/*name*/
|
|
160126
|
+
/*name*/ parameterName + (parameterNameCount || ""),
|
|
160017
160127
|
/*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
|
|
160018
|
-
/*type*/ inJs ? undefined : types
|
|
160128
|
+
/*type*/ inJs ? undefined : (types === null || types === void 0 ? void 0 : types[i]) || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
|
|
160019
160129
|
/*initializer*/ undefined);
|
|
160020
160130
|
parameters.push(newParameter);
|
|
160021
160131
|
}
|
|
@@ -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.20220727";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -8762,6 +8762,7 @@ var ts;
|
|
|
8762
8762
|
Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
|
|
8763
8763
|
auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
|
|
8764
8764
|
An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
|
|
8765
|
+
Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
|
|
8765
8766
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
8766
8767
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
8767
8768
|
Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
@@ -33501,7 +33502,9 @@ var ts;
|
|
|
33501
33502
|
case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33502
33503
|
case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33503
33504
|
case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33504
|
-
|
|
33505
|
+
case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
|
|
33506
|
+
case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
|
|
33507
|
+
default: ts.Debug.assertNever(context);
|
|
33505
33508
|
}
|
|
33506
33509
|
}
|
|
33507
33510
|
function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
|
|
@@ -72133,8 +72136,12 @@ var ts;
|
|
|
72133
72136
|
var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
|
|
72134
72137
|
var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
|
|
72135
72138
|
// For each constituent t in the current type, if t and and c are directly related, pick the most
|
|
72136
|
-
// specific of the two.
|
|
72137
|
-
|
|
72139
|
+
// specific of the two. When t and c are related in both directions, we prefer c for type predicates
|
|
72140
|
+
// because that is the asserted type, but t for `instanceof` because generics aren't reflected in
|
|
72141
|
+
// prototype object types.
|
|
72142
|
+
var directlyRelated = mapType(matching || type, checkDerived ?
|
|
72143
|
+
function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
|
|
72144
|
+
function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
|
|
72138
72145
|
// If no constituents are directly related, create intersections for any generic constituents that
|
|
72139
72146
|
// are related by constraint.
|
|
72140
72147
|
return directlyRelated.flags & 131072 /* Never */ ?
|
|
@@ -155993,8 +156000,7 @@ var ts;
|
|
|
155993
156000
|
codefix.eachDiagnostic(context, errorCodes, function (diag) {
|
|
155994
156001
|
var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
|
|
155995
156002
|
if (info) {
|
|
155996
|
-
|
|
155997
|
-
if (ts.addToSeen(seen, id)) {
|
|
156003
|
+
if (ts.addToSeen(seen, ts.getNodeId(info.declaration))) {
|
|
155998
156004
|
return addMissingConstraint(changes, program, preferences, host, diag.file, info);
|
|
155999
156005
|
}
|
|
156000
156006
|
}
|
|
@@ -159962,21 +159968,16 @@ var ts;
|
|
|
159962
159968
|
var names = ts.map(args, function (arg) {
|
|
159963
159969
|
return ts.isIdentifier(arg) ? arg.text : ts.isPropertyAccessExpression(arg) && ts.isIdentifier(arg.name) ? arg.name.text : undefined;
|
|
159964
159970
|
});
|
|
159965
|
-
var
|
|
159966
|
-
|
|
159967
|
-
});
|
|
159971
|
+
var instanceTypes = isJs ? [] : ts.map(args, function (arg) { return checker.getTypeAtLocation(arg); });
|
|
159972
|
+
var _a = getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, /*flags*/ undefined, tracker), argumentTypeNodes = _a.argumentTypeNodes, argumentTypeParameters = _a.argumentTypeParameters;
|
|
159968
159973
|
var modifiers = modifierFlags
|
|
159969
159974
|
? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags))
|
|
159970
159975
|
: undefined;
|
|
159971
159976
|
var asteriskToken = ts.isYieldExpression(parent)
|
|
159972
159977
|
? ts.factory.createToken(41 /* AsteriskToken */)
|
|
159973
159978
|
: undefined;
|
|
159974
|
-
var typeParameters = isJs
|
|
159975
|
-
|
|
159976
|
-
: ts.map(typeArguments, function (_, i) {
|
|
159977
|
-
return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, 84 /* T */ + typeArguments.length - 1 <= 90 /* Z */ ? String.fromCharCode(84 /* T */ + i) : "T" + i);
|
|
159978
|
-
});
|
|
159979
|
-
var parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
|
|
159979
|
+
var typeParameters = isJs ? undefined : createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments);
|
|
159980
|
+
var parameters = createDummyParameters(args.length, names, argumentTypeNodes, /*minArgumentCount*/ undefined, isJs);
|
|
159980
159981
|
var type = isJs || contextualType === undefined
|
|
159981
159982
|
? undefined
|
|
159982
159983
|
: checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
|
|
@@ -159994,6 +159995,23 @@ var ts;
|
|
|
159994
159995
|
}
|
|
159995
159996
|
}
|
|
159996
159997
|
codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
|
|
159998
|
+
function createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments) {
|
|
159999
|
+
var usedNames = new ts.Set(argumentTypeParameters.map(function (pair) { return pair[0]; }));
|
|
160000
|
+
var constraintsByName = new ts.Map(argumentTypeParameters);
|
|
160001
|
+
if (typeArguments) {
|
|
160002
|
+
var typeArgumentsWithNewTypes = typeArguments.filter(function (typeArgument) { return !argumentTypeParameters.some(function (pair) { var _a; return checker.getTypeAtLocation(typeArgument) === ((_a = pair[1]) === null || _a === void 0 ? void 0 : _a.argumentType); }); });
|
|
160003
|
+
var targetSize = usedNames.size + typeArgumentsWithNewTypes.length;
|
|
160004
|
+
for (var i = 0; usedNames.size < targetSize; i += 1) {
|
|
160005
|
+
usedNames.add(createTypeParameterName(i));
|
|
160006
|
+
}
|
|
160007
|
+
}
|
|
160008
|
+
return ts.map(ts.arrayFrom(usedNames.values()), function (usedName) { var _a; return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, usedName, (_a = constraintsByName.get(usedName)) === null || _a === void 0 ? void 0 : _a.constraint); });
|
|
160009
|
+
}
|
|
160010
|
+
function createTypeParameterName(index) {
|
|
160011
|
+
return 84 /* T */ + index <= 90 /* Z */
|
|
160012
|
+
? String.fromCharCode(84 /* T */ + index)
|
|
160013
|
+
: "T" + index;
|
|
160014
|
+
}
|
|
159997
160015
|
function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
|
|
159998
160016
|
var typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
|
|
159999
160017
|
if (typeNode && ts.isImportTypeNode(typeNode)) {
|
|
@@ -160007,15 +160025,107 @@ var ts;
|
|
|
160007
160025
|
return ts.getSynthesizedDeepClone(typeNode);
|
|
160008
160026
|
}
|
|
160009
160027
|
codefix.typeToAutoImportableTypeNode = typeToAutoImportableTypeNode;
|
|
160028
|
+
function typeContainsTypeParameter(type) {
|
|
160029
|
+
if (type.isUnionOrIntersection()) {
|
|
160030
|
+
return type.types.some(typeContainsTypeParameter);
|
|
160031
|
+
}
|
|
160032
|
+
return type.flags & 262144 /* TypeParameter */;
|
|
160033
|
+
}
|
|
160034
|
+
function getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, flags, tracker) {
|
|
160035
|
+
// Types to be used as the types of the parameters in the new function
|
|
160036
|
+
// E.g. from this source:
|
|
160037
|
+
// added("", 0)
|
|
160038
|
+
// The value will look like:
|
|
160039
|
+
// [{ typeName: { text: "string" } }, { typeName: { text: "number" }]
|
|
160040
|
+
// And in the output function will generate:
|
|
160041
|
+
// function added(a: string, b: number) { ... }
|
|
160042
|
+
var argumentTypeNodes = [];
|
|
160043
|
+
// Names of type parameters provided as arguments to the call
|
|
160044
|
+
// E.g. from this source:
|
|
160045
|
+
// added<T, U>(value);
|
|
160046
|
+
// The value will look like:
|
|
160047
|
+
// [
|
|
160048
|
+
// ["T", { argumentType: { typeName: { text: "T" } } } ],
|
|
160049
|
+
// ["U", { argumentType: { typeName: { text: "U" } } } ],
|
|
160050
|
+
// ]
|
|
160051
|
+
// And in the output function will generate:
|
|
160052
|
+
// function added<T, U>() { ... }
|
|
160053
|
+
var argumentTypeParameters = new ts.Map();
|
|
160054
|
+
for (var i = 0; i < instanceTypes.length; i += 1) {
|
|
160055
|
+
var instanceType = instanceTypes[i];
|
|
160056
|
+
// If the instance type contains a deep reference to an existing type parameter,
|
|
160057
|
+
// instead of copying the full union or intersection, create a new type parameter
|
|
160058
|
+
// E.g. from this source:
|
|
160059
|
+
// function existing<T, U>(value: T | U & string) {
|
|
160060
|
+
// added/*1*/(value);
|
|
160061
|
+
// We don't want to output this:
|
|
160062
|
+
// function added<T>(value: T | U & string) { ... }
|
|
160063
|
+
// We instead want to output:
|
|
160064
|
+
// function added<T>(value: T) { ... }
|
|
160065
|
+
if (instanceType.isUnionOrIntersection() && instanceType.types.some(typeContainsTypeParameter)) {
|
|
160066
|
+
var synthesizedTypeParameterName = createTypeParameterName(i);
|
|
160067
|
+
argumentTypeNodes.push(ts.factory.createTypeReferenceNode(synthesizedTypeParameterName));
|
|
160068
|
+
argumentTypeParameters.set(synthesizedTypeParameterName, undefined);
|
|
160069
|
+
continue;
|
|
160070
|
+
}
|
|
160071
|
+
// Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
|
|
160072
|
+
var widenedInstanceType = checker.getBaseTypeOfLiteralType(instanceType);
|
|
160073
|
+
var argumentTypeNode = typeToAutoImportableTypeNode(checker, importAdder, widenedInstanceType, contextNode, scriptTarget, flags, tracker);
|
|
160074
|
+
if (!argumentTypeNode) {
|
|
160075
|
+
continue;
|
|
160076
|
+
}
|
|
160077
|
+
argumentTypeNodes.push(argumentTypeNode);
|
|
160078
|
+
var argumentTypeParameter = getFirstTypeParameterName(instanceType);
|
|
160079
|
+
// If the instance type is a type parameter with a constraint (other than an anonymous object),
|
|
160080
|
+
// remember that constraint for when we create the new type parameter
|
|
160081
|
+
// E.g. from this source:
|
|
160082
|
+
// function existing<T extends string>(value: T) {
|
|
160083
|
+
// added/*1*/(value);
|
|
160084
|
+
// We don't want to output this:
|
|
160085
|
+
// function added<T>(value: T) { ... }
|
|
160086
|
+
// We instead want to output:
|
|
160087
|
+
// function added<T extends string>(value: T) { ... }
|
|
160088
|
+
var instanceTypeConstraint = instanceType.isTypeParameter() && instanceType.constraint && !isAnonymousObjectConstraintType(instanceType.constraint)
|
|
160089
|
+
? typeToAutoImportableTypeNode(checker, importAdder, instanceType.constraint, contextNode, scriptTarget, flags, tracker)
|
|
160090
|
+
: undefined;
|
|
160091
|
+
if (argumentTypeParameter) {
|
|
160092
|
+
argumentTypeParameters.set(argumentTypeParameter, { argumentType: instanceType, constraint: instanceTypeConstraint });
|
|
160093
|
+
}
|
|
160094
|
+
}
|
|
160095
|
+
return { argumentTypeNodes: argumentTypeNodes, argumentTypeParameters: ts.arrayFrom(argumentTypeParameters.entries()) };
|
|
160096
|
+
}
|
|
160097
|
+
codefix.getArgumentTypesAndTypeParameters = getArgumentTypesAndTypeParameters;
|
|
160098
|
+
function isAnonymousObjectConstraintType(type) {
|
|
160099
|
+
return (type.flags & 524288 /* Object */) && type.objectFlags === 16 /* Anonymous */;
|
|
160100
|
+
}
|
|
160101
|
+
function getFirstTypeParameterName(type) {
|
|
160102
|
+
var _a;
|
|
160103
|
+
if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
|
|
160104
|
+
for (var _i = 0, _b = type.types; _i < _b.length; _i++) {
|
|
160105
|
+
var subType = _b[_i];
|
|
160106
|
+
var subTypeName = getFirstTypeParameterName(subType);
|
|
160107
|
+
if (subTypeName) {
|
|
160108
|
+
return subTypeName;
|
|
160109
|
+
}
|
|
160110
|
+
}
|
|
160111
|
+
}
|
|
160112
|
+
return type.flags & 262144 /* TypeParameter */
|
|
160113
|
+
? (_a = type.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName()
|
|
160114
|
+
: undefined;
|
|
160115
|
+
}
|
|
160010
160116
|
function createDummyParameters(argCount, names, types, minArgumentCount, inJs) {
|
|
160011
160117
|
var parameters = [];
|
|
160118
|
+
var parameterNameCounts = new ts.Map();
|
|
160012
160119
|
for (var i = 0; i < argCount; i++) {
|
|
160120
|
+
var parameterName = (names === null || names === void 0 ? void 0 : names[i]) || "arg" + i;
|
|
160121
|
+
var parameterNameCount = parameterNameCounts.get(parameterName);
|
|
160122
|
+
parameterNameCounts.set(parameterName, (parameterNameCount || 0) + 1);
|
|
160013
160123
|
var newParameter = ts.factory.createParameterDeclaration(
|
|
160014
160124
|
/*modifiers*/ undefined,
|
|
160015
160125
|
/*dotDotDotToken*/ undefined,
|
|
160016
|
-
/*name*/
|
|
160126
|
+
/*name*/ parameterName + (parameterNameCount || ""),
|
|
160017
160127
|
/*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
|
|
160018
|
-
/*type*/ inJs ? undefined : types
|
|
160128
|
+
/*type*/ inJs ? undefined : (types === null || types === void 0 ? void 0 : types[i]) || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
|
|
160019
160129
|
/*initializer*/ undefined);
|
|
160020
160130
|
parameters.push(newParameter);
|
|
160021
160131
|
}
|
package/lib/typingsInstaller.js
CHANGED
|
@@ -89,7 +89,7 @@ var ts;
|
|
|
89
89
|
// The following is baselined as a literal template type without intervention
|
|
90
90
|
/** The version of the TypeScript compiler release */
|
|
91
91
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
92
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
92
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220727";
|
|
93
93
|
/* @internal */
|
|
94
94
|
var Comparison;
|
|
95
95
|
(function (Comparison) {
|
|
@@ -8557,6 +8557,7 @@ var ts;
|
|
|
8557
8557
|
Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
|
|
8558
8558
|
auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
|
|
8559
8559
|
An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
|
|
8560
|
+
Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
|
|
8560
8561
|
The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
|
|
8561
8562
|
The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
|
|
8562
8563
|
Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
|
|
@@ -33296,7 +33297,9 @@ var ts;
|
|
|
33296
33297
|
case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33297
33298
|
case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33298
33299
|
case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
|
|
33299
|
-
|
|
33300
|
+
case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
|
|
33301
|
+
case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
|
|
33302
|
+
default: ts.Debug.assertNever(context);
|
|
33300
33303
|
}
|
|
33301
33304
|
}
|
|
33302
33305
|
function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
|
|
@@ -71928,8 +71931,12 @@ var ts;
|
|
|
71928
71931
|
var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
|
|
71929
71932
|
var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
|
|
71930
71933
|
// For each constituent t in the current type, if t and and c are directly related, pick the most
|
|
71931
|
-
// specific of the two.
|
|
71932
|
-
|
|
71934
|
+
// specific of the two. When t and c are related in both directions, we prefer c for type predicates
|
|
71935
|
+
// because that is the asserted type, but t for `instanceof` because generics aren't reflected in
|
|
71936
|
+
// prototype object types.
|
|
71937
|
+
var directlyRelated = mapType(matching || type, checkDerived ?
|
|
71938
|
+
function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
|
|
71939
|
+
function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
|
|
71933
71940
|
// If no constituents are directly related, create intersections for any generic constituents that
|
|
71934
71941
|
// are related by constraint.
|
|
71935
71942
|
return directlyRelated.flags & 131072 /* Never */ ?
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "typescript",
|
|
3
3
|
"author": "Microsoft Corp.",
|
|
4
4
|
"homepage": "https://www.typescriptlang.org/",
|
|
5
|
-
"version": "4.8.0-dev.
|
|
5
|
+
"version": "4.8.0-dev.20220727",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"description": "TypeScript is a language for application scale JavaScript development",
|
|
8
8
|
"keywords": [
|