typedoc 0.22.13 → 0.22.16
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/README.md +2 -2
- package/dist/lib/converter/context.d.ts +2 -0
- package/dist/lib/converter/context.js +6 -0
- package/dist/lib/converter/converter.js +6 -1
- package/dist/lib/converter/factories/signature.d.ts +1 -0
- package/dist/lib/converter/factories/signature.js +33 -14
- package/dist/lib/converter/plugins/CategoryPlugin.d.ts +10 -4
- package/dist/lib/converter/plugins/CategoryPlugin.js +24 -14
- package/dist/lib/converter/plugins/CommentPlugin.js +9 -4
- package/dist/lib/converter/plugins/GroupPlugin.js +3 -3
- package/dist/lib/converter/plugins/PackagePlugin.js +27 -3
- package/dist/lib/converter/symbols.js +29 -29
- package/dist/lib/converter/types.js +10 -4
- package/dist/lib/models/reflections/abstract.d.ts +7 -1
- package/dist/lib/models/reflections/abstract.js +20 -1
- package/dist/lib/models/reflections/container.d.ts +5 -0
- package/dist/lib/models/reflections/container.js +1 -1
- package/dist/lib/models/reflections/declaration.d.ts +2 -0
- package/dist/lib/models/reflections/declaration.js +2 -2
- package/dist/lib/models/reflections/index.d.ts +1 -1
- package/dist/lib/models/reflections/index.js +2 -1
- package/dist/lib/models/reflections/signature.js +2 -2
- package/dist/lib/models/reflections/type-parameter.d.ts +12 -4
- package/dist/lib/models/reflections/type-parameter.js +12 -5
- package/dist/lib/models/types.d.ts +92 -23
- package/dist/lib/models/types.js +327 -78
- package/dist/lib/output/plugins/JavascriptIndexPlugin.js +18 -8
- package/dist/lib/output/plugins/LegendPlugin.js +1 -1
- package/dist/lib/output/plugins/MarkedLinksPlugin.js +1 -1
- package/dist/lib/output/renderer.d.ts +16 -0
- package/dist/lib/output/themes/default/layouts/default.js +8 -2
- package/dist/lib/output/themes/default/partials/header.js +3 -1
- package/dist/lib/output/themes/default/partials/member.declaration.js +2 -2
- package/dist/lib/output/themes/default/partials/member.signature.body.js +1 -1
- package/dist/lib/output/themes/default/partials/type.js +46 -44
- package/dist/lib/output/themes/default/partials/typeParameters.js +2 -1
- package/dist/lib/output/themes/default/templates/reflection.js +1 -1
- package/dist/lib/output/themes/lib.js +3 -1
- package/dist/lib/serialization/schema.d.ts +2 -2
- package/dist/lib/serialization/serializers/reflections/type-parameter.js +1 -0
- package/dist/lib/serialization/serializers/types/inferred.js +3 -0
- package/dist/lib/utils/entry-point.d.ts +1 -1
- package/dist/lib/utils/entry-point.js +6 -6
- package/dist/lib/utils/options/declaration.d.ts +14 -1
- package/dist/lib/utils/options/declaration.js +2 -0
- package/dist/lib/utils/options/options.js +5 -1
- package/dist/lib/utils/options/sources/typedoc.js +49 -5
- package/dist/lib/utils/package-manifest.js +1 -1
- package/dist/lib/utils/sort.d.ts +1 -1
- package/dist/lib/utils/sort.js +10 -9
- package/dist/lib/validation/documentation.js +55 -9
- package/package.json +16 -16
- package/static/main.js +2 -2
- package/static/style.css +3 -2
package/dist/lib/models/types.js
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnknownType = exports.UnionType = exports.TypeOperatorType = exports.NamedTupleMember = exports.TupleType = exports.TemplateLiteralType = exports.RestType = exports.ReflectionType = exports.ReferenceType = exports.QueryType = exports.PredicateType = exports.OptionalType = exports.MappedType = exports.LiteralType = exports.IntrinsicType = exports.IntersectionType = exports.InferredType = exports.IndexedAccessType = exports.ConditionalType = exports.ArrayType = exports.makeRecursiveVisitor = exports.Type = void 0;
|
|
3
|
+
exports.UnknownType = exports.UnionType = exports.TypeOperatorType = exports.NamedTupleMember = exports.TupleType = exports.TemplateLiteralType = exports.RestType = exports.ReflectionType = exports.ReferenceType = exports.QueryType = exports.PredicateType = exports.OptionalType = exports.MappedType = exports.LiteralType = exports.IntrinsicType = exports.IntersectionType = exports.InferredType = exports.IndexedAccessType = exports.ConditionalType = exports.ArrayType = exports.TypeContext = exports.makeRecursiveVisitor = exports.Type = void 0;
|
|
4
4
|
const abstract_1 = require("./reflections/abstract");
|
|
5
5
|
/**
|
|
6
6
|
* Base class of all type definitions.
|
|
7
7
|
*/
|
|
8
8
|
class Type {
|
|
9
|
+
/**
|
|
10
|
+
* Return a string representation of this type.
|
|
11
|
+
*/
|
|
12
|
+
toString() {
|
|
13
|
+
return this.stringify(exports.TypeContext.none);
|
|
14
|
+
}
|
|
9
15
|
visit(visitor) {
|
|
10
16
|
var _a;
|
|
11
17
|
return (_a = visitor[this.type]) === null || _a === void 0 ? void 0 : _a.call(visitor, this);
|
|
12
18
|
}
|
|
19
|
+
stringify(context) {
|
|
20
|
+
if (this.needsParenthesis(context)) {
|
|
21
|
+
return `(${this.getTypeString()})`;
|
|
22
|
+
}
|
|
23
|
+
return this.getTypeString();
|
|
24
|
+
}
|
|
13
25
|
}
|
|
14
26
|
exports.Type = Type;
|
|
15
27
|
function makeRecursiveVisitor(visitor) {
|
|
@@ -46,10 +58,13 @@ function makeRecursiveVisitor(visitor) {
|
|
|
46
58
|
type.objectType.visit(recursiveVisitor);
|
|
47
59
|
},
|
|
48
60
|
inferred(type) {
|
|
49
|
-
var _a;
|
|
61
|
+
var _a, _b;
|
|
50
62
|
(_a = visitor.inferred) === null || _a === void 0 ? void 0 : _a.call(visitor, type);
|
|
63
|
+
(_b = type.constraint) === null || _b === void 0 ? void 0 : _b.visit(recursiveVisitor);
|
|
51
64
|
},
|
|
52
65
|
intersection(type) {
|
|
66
|
+
var _a;
|
|
67
|
+
(_a = visitor.intersection) === null || _a === void 0 ? void 0 : _a.call(visitor, type);
|
|
53
68
|
type.types.forEach((t) => t.visit(recursiveVisitor));
|
|
54
69
|
},
|
|
55
70
|
intrinsic(type) {
|
|
@@ -121,40 +136,36 @@ function makeRecursiveVisitor(visitor) {
|
|
|
121
136
|
return recursiveVisitor;
|
|
122
137
|
}
|
|
123
138
|
exports.makeRecursiveVisitor = makeRecursiveVisitor;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
"
|
|
145
|
-
|
|
146
|
-
"
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Enumeration that can be used when traversing types to track the location of recursion.
|
|
141
|
+
* Used by TypeDoc internally to track when to output parenthesis when rendering.
|
|
142
|
+
* @enum
|
|
143
|
+
*/
|
|
144
|
+
exports.TypeContext = {
|
|
145
|
+
none: "none",
|
|
146
|
+
templateLiteralElement: "templateLiteralElement",
|
|
147
|
+
arrayElement: "arrayElement",
|
|
148
|
+
indexedAccessElement: "indexedAccessElement",
|
|
149
|
+
conditionalCheck: "conditionalCheck",
|
|
150
|
+
conditionalExtends: "conditionalExtends",
|
|
151
|
+
conditionalTrue: "conditionalTrue",
|
|
152
|
+
conditionalFalse: "conditionalFalse",
|
|
153
|
+
indexedIndex: "indexedIndex",
|
|
154
|
+
indexedObject: "indexedObject",
|
|
155
|
+
inferredConstraint: "inferredConstraint",
|
|
156
|
+
intersectionElement: "intersectionElement",
|
|
157
|
+
mappedName: "mappedName",
|
|
158
|
+
mappedParameter: "mappedParameter",
|
|
159
|
+
mappedTemplate: "mappedTemplate",
|
|
160
|
+
optionalElement: "optionalElement",
|
|
161
|
+
predicateTarget: "predicateTarget",
|
|
162
|
+
queryTypeTarget: "queryTypeTarget",
|
|
163
|
+
typeOperatorTarget: "typeOperatorTarget",
|
|
164
|
+
referenceTypeArgument: "referenceTypeArgument",
|
|
165
|
+
restElement: "restElement",
|
|
166
|
+
tupleElement: "tupleElement",
|
|
167
|
+
unionElement: "unionElement", // here | 1
|
|
151
168
|
};
|
|
152
|
-
function wrap(type, bp) {
|
|
153
|
-
if (BINDING_POWERS[type.type] < bp) {
|
|
154
|
-
return `(${type})`;
|
|
155
|
-
}
|
|
156
|
-
return type.toString();
|
|
157
|
-
}
|
|
158
169
|
/**
|
|
159
170
|
* Represents an array type.
|
|
160
171
|
*
|
|
@@ -168,8 +179,11 @@ class ArrayType extends Type {
|
|
|
168
179
|
this.type = "array";
|
|
169
180
|
this.elementType = elementType;
|
|
170
181
|
}
|
|
171
|
-
|
|
172
|
-
return
|
|
182
|
+
getTypeString() {
|
|
183
|
+
return this.elementType.stringify(exports.TypeContext.arrayElement) + "[]";
|
|
184
|
+
}
|
|
185
|
+
needsParenthesis() {
|
|
186
|
+
return false;
|
|
173
187
|
}
|
|
174
188
|
}
|
|
175
189
|
exports.ArrayType = ArrayType;
|
|
@@ -189,17 +203,45 @@ class ConditionalType extends Type {
|
|
|
189
203
|
this.falseType = falseType;
|
|
190
204
|
this.type = "conditional";
|
|
191
205
|
}
|
|
192
|
-
|
|
206
|
+
getTypeString() {
|
|
193
207
|
return [
|
|
194
|
-
|
|
208
|
+
this.checkType.stringify(exports.TypeContext.conditionalCheck),
|
|
195
209
|
"extends",
|
|
196
|
-
this.extendsType,
|
|
210
|
+
this.extendsType.stringify(exports.TypeContext.conditionalExtends),
|
|
197
211
|
"?",
|
|
198
|
-
this.trueType,
|
|
212
|
+
this.trueType.stringify(exports.TypeContext.conditionalTrue),
|
|
199
213
|
":",
|
|
200
|
-
this.falseType,
|
|
214
|
+
this.falseType.stringify(exports.TypeContext.conditionalFalse),
|
|
201
215
|
].join(" ");
|
|
202
216
|
}
|
|
217
|
+
needsParenthesis(context) {
|
|
218
|
+
const map = {
|
|
219
|
+
none: false,
|
|
220
|
+
templateLiteralElement: false,
|
|
221
|
+
arrayElement: true,
|
|
222
|
+
indexedAccessElement: false,
|
|
223
|
+
conditionalCheck: true,
|
|
224
|
+
conditionalExtends: true,
|
|
225
|
+
conditionalTrue: false,
|
|
226
|
+
conditionalFalse: false,
|
|
227
|
+
indexedIndex: false,
|
|
228
|
+
indexedObject: true,
|
|
229
|
+
inferredConstraint: true,
|
|
230
|
+
intersectionElement: true,
|
|
231
|
+
mappedName: false,
|
|
232
|
+
mappedParameter: false,
|
|
233
|
+
mappedTemplate: false,
|
|
234
|
+
optionalElement: true,
|
|
235
|
+
predicateTarget: false,
|
|
236
|
+
queryTypeTarget: false,
|
|
237
|
+
typeOperatorTarget: true,
|
|
238
|
+
referenceTypeArgument: false,
|
|
239
|
+
restElement: true,
|
|
240
|
+
tupleElement: false,
|
|
241
|
+
unionElement: true,
|
|
242
|
+
};
|
|
243
|
+
return map[context];
|
|
244
|
+
}
|
|
203
245
|
}
|
|
204
246
|
exports.ConditionalType = ConditionalType;
|
|
205
247
|
/**
|
|
@@ -212,8 +254,16 @@ class IndexedAccessType extends Type {
|
|
|
212
254
|
this.indexType = indexType;
|
|
213
255
|
this.type = "indexedAccess";
|
|
214
256
|
}
|
|
215
|
-
|
|
216
|
-
return
|
|
257
|
+
getTypeString() {
|
|
258
|
+
return [
|
|
259
|
+
this.objectType.stringify(exports.TypeContext.indexedObject),
|
|
260
|
+
"[",
|
|
261
|
+
this.indexType.stringify(exports.TypeContext.indexedIndex),
|
|
262
|
+
"]",
|
|
263
|
+
].join("");
|
|
264
|
+
}
|
|
265
|
+
needsParenthesis() {
|
|
266
|
+
return false;
|
|
217
267
|
}
|
|
218
268
|
}
|
|
219
269
|
exports.IndexedAccessType = IndexedAccessType;
|
|
@@ -225,14 +275,46 @@ exports.IndexedAccessType = IndexedAccessType;
|
|
|
225
275
|
* ```
|
|
226
276
|
*/
|
|
227
277
|
class InferredType extends Type {
|
|
228
|
-
constructor(name) {
|
|
278
|
+
constructor(name, constraint) {
|
|
229
279
|
super();
|
|
230
280
|
this.name = name;
|
|
281
|
+
this.constraint = constraint;
|
|
231
282
|
this.type = "inferred";
|
|
232
283
|
}
|
|
233
|
-
|
|
284
|
+
getTypeString() {
|
|
285
|
+
if (this.constraint) {
|
|
286
|
+
return `infer ${this.name} extends ${this.constraint.stringify(exports.TypeContext.inferredConstraint)}`;
|
|
287
|
+
}
|
|
234
288
|
return `infer ${this.name}`;
|
|
235
289
|
}
|
|
290
|
+
needsParenthesis(context) {
|
|
291
|
+
const map = {
|
|
292
|
+
none: false,
|
|
293
|
+
templateLiteralElement: false,
|
|
294
|
+
arrayElement: true,
|
|
295
|
+
indexedAccessElement: false,
|
|
296
|
+
conditionalCheck: false,
|
|
297
|
+
conditionalExtends: false,
|
|
298
|
+
conditionalTrue: false,
|
|
299
|
+
conditionalFalse: false,
|
|
300
|
+
indexedIndex: false,
|
|
301
|
+
indexedObject: true,
|
|
302
|
+
inferredConstraint: false,
|
|
303
|
+
intersectionElement: false,
|
|
304
|
+
mappedName: false,
|
|
305
|
+
mappedParameter: false,
|
|
306
|
+
mappedTemplate: false,
|
|
307
|
+
optionalElement: true,
|
|
308
|
+
predicateTarget: false,
|
|
309
|
+
queryTypeTarget: false,
|
|
310
|
+
typeOperatorTarget: false,
|
|
311
|
+
referenceTypeArgument: false,
|
|
312
|
+
restElement: true,
|
|
313
|
+
tupleElement: false,
|
|
314
|
+
unionElement: false,
|
|
315
|
+
};
|
|
316
|
+
return map[context];
|
|
317
|
+
}
|
|
236
318
|
}
|
|
237
319
|
exports.InferredType = InferredType;
|
|
238
320
|
/**
|
|
@@ -248,11 +330,39 @@ class IntersectionType extends Type {
|
|
|
248
330
|
this.types = types;
|
|
249
331
|
this.type = "intersection";
|
|
250
332
|
}
|
|
251
|
-
|
|
333
|
+
getTypeString() {
|
|
252
334
|
return this.types
|
|
253
|
-
.map((t) =>
|
|
335
|
+
.map((t) => t.stringify(exports.TypeContext.intersectionElement))
|
|
254
336
|
.join(" & ");
|
|
255
337
|
}
|
|
338
|
+
needsParenthesis(context) {
|
|
339
|
+
const map = {
|
|
340
|
+
none: false,
|
|
341
|
+
templateLiteralElement: false,
|
|
342
|
+
arrayElement: true,
|
|
343
|
+
indexedAccessElement: false,
|
|
344
|
+
conditionalCheck: true,
|
|
345
|
+
conditionalExtends: false,
|
|
346
|
+
conditionalTrue: false,
|
|
347
|
+
conditionalFalse: false,
|
|
348
|
+
indexedIndex: false,
|
|
349
|
+
indexedObject: true,
|
|
350
|
+
inferredConstraint: false,
|
|
351
|
+
intersectionElement: false,
|
|
352
|
+
mappedName: false,
|
|
353
|
+
mappedParameter: false,
|
|
354
|
+
mappedTemplate: false,
|
|
355
|
+
optionalElement: true,
|
|
356
|
+
predicateTarget: false,
|
|
357
|
+
queryTypeTarget: false,
|
|
358
|
+
typeOperatorTarget: true,
|
|
359
|
+
referenceTypeArgument: false,
|
|
360
|
+
restElement: true,
|
|
361
|
+
tupleElement: false,
|
|
362
|
+
unionElement: false,
|
|
363
|
+
};
|
|
364
|
+
return map[context];
|
|
365
|
+
}
|
|
256
366
|
}
|
|
257
367
|
exports.IntersectionType = IntersectionType;
|
|
258
368
|
/**
|
|
@@ -268,9 +378,12 @@ class IntrinsicType extends Type {
|
|
|
268
378
|
this.name = name;
|
|
269
379
|
this.type = "intrinsic";
|
|
270
380
|
}
|
|
271
|
-
|
|
381
|
+
getTypeString() {
|
|
272
382
|
return this.name;
|
|
273
383
|
}
|
|
384
|
+
needsParenthesis() {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
274
387
|
}
|
|
275
388
|
exports.IntrinsicType = IntrinsicType;
|
|
276
389
|
/**
|
|
@@ -290,19 +403,22 @@ class LiteralType extends Type {
|
|
|
290
403
|
/**
|
|
291
404
|
* Return a string representation of this type.
|
|
292
405
|
*/
|
|
293
|
-
|
|
406
|
+
getTypeString() {
|
|
294
407
|
if (typeof this.value === "bigint") {
|
|
295
408
|
return this.value.toString() + "n";
|
|
296
409
|
}
|
|
297
410
|
return JSON.stringify(this.value);
|
|
298
411
|
}
|
|
412
|
+
needsParenthesis() {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
299
415
|
}
|
|
300
416
|
exports.LiteralType = LiteralType;
|
|
301
417
|
/**
|
|
302
418
|
* Represents a mapped type.
|
|
303
419
|
*
|
|
304
420
|
* ```ts
|
|
305
|
-
* { -readonly [K in
|
|
421
|
+
* { -readonly [K in Parameter as Name]?: Template }
|
|
306
422
|
* ```
|
|
307
423
|
*/
|
|
308
424
|
class MappedType extends Type {
|
|
@@ -316,7 +432,7 @@ class MappedType extends Type {
|
|
|
316
432
|
this.nameType = nameType;
|
|
317
433
|
this.type = "mapped";
|
|
318
434
|
}
|
|
319
|
-
|
|
435
|
+
getTypeString() {
|
|
320
436
|
var _a, _b;
|
|
321
437
|
const read = {
|
|
322
438
|
"+": "readonly ",
|
|
@@ -328,8 +444,22 @@ class MappedType extends Type {
|
|
|
328
444
|
"-": "-?",
|
|
329
445
|
"": "",
|
|
330
446
|
}[(_b = this.optionalModifier) !== null && _b !== void 0 ? _b : ""];
|
|
331
|
-
const
|
|
332
|
-
|
|
447
|
+
const parts = [
|
|
448
|
+
"{ ",
|
|
449
|
+
read,
|
|
450
|
+
"[",
|
|
451
|
+
this.parameter,
|
|
452
|
+
" in ",
|
|
453
|
+
this.parameterType.stringify(exports.TypeContext.mappedParameter),
|
|
454
|
+
];
|
|
455
|
+
if (this.nameType) {
|
|
456
|
+
parts.push(" as ", this.nameType.stringify(exports.TypeContext.mappedName));
|
|
457
|
+
}
|
|
458
|
+
parts.push("]", opt, ": ", this.templateType.stringify(exports.TypeContext.mappedTemplate), " }");
|
|
459
|
+
return parts.join("");
|
|
460
|
+
}
|
|
461
|
+
needsParenthesis() {
|
|
462
|
+
return false;
|
|
333
463
|
}
|
|
334
464
|
}
|
|
335
465
|
exports.MappedType = MappedType;
|
|
@@ -346,8 +476,11 @@ class OptionalType extends Type {
|
|
|
346
476
|
this.type = "optional";
|
|
347
477
|
this.elementType = elementType;
|
|
348
478
|
}
|
|
349
|
-
|
|
350
|
-
return
|
|
479
|
+
getTypeString() {
|
|
480
|
+
return this.elementType.stringify(exports.TypeContext.optionalElement) + "?";
|
|
481
|
+
}
|
|
482
|
+
needsParenthesis() {
|
|
483
|
+
return false;
|
|
351
484
|
}
|
|
352
485
|
}
|
|
353
486
|
exports.OptionalType = OptionalType;
|
|
@@ -373,13 +506,16 @@ class PredicateType extends Type {
|
|
|
373
506
|
/**
|
|
374
507
|
* Return a string representation of this type.
|
|
375
508
|
*/
|
|
376
|
-
|
|
509
|
+
getTypeString() {
|
|
377
510
|
const out = this.asserts ? ["asserts", this.name] : [this.name];
|
|
378
511
|
if (this.targetType) {
|
|
379
|
-
out.push("is", this.targetType.
|
|
512
|
+
out.push("is", this.targetType.stringify(exports.TypeContext.predicateTarget));
|
|
380
513
|
}
|
|
381
514
|
return out.join(" ");
|
|
382
515
|
}
|
|
516
|
+
needsParenthesis() {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
383
519
|
}
|
|
384
520
|
exports.PredicateType = PredicateType;
|
|
385
521
|
/**
|
|
@@ -395,8 +531,17 @@ class QueryType extends Type {
|
|
|
395
531
|
this.type = "query";
|
|
396
532
|
this.queryType = reference;
|
|
397
533
|
}
|
|
398
|
-
|
|
399
|
-
return `typeof ${this.queryType.
|
|
534
|
+
getTypeString() {
|
|
535
|
+
return `typeof ${this.queryType.stringify(exports.TypeContext.queryTypeTarget)}`;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* @privateRemarks
|
|
539
|
+
* An argument could be made that this ought to return true for indexedObject
|
|
540
|
+
* since precedence is different than on the value side... if someone really cares
|
|
541
|
+
* they can easily use a custom theme to change this.
|
|
542
|
+
*/
|
|
543
|
+
needsParenthesis() {
|
|
544
|
+
return false;
|
|
400
545
|
}
|
|
401
546
|
}
|
|
402
547
|
exports.QueryType = QueryType;
|
|
@@ -477,18 +622,21 @@ class ReferenceType extends Type {
|
|
|
477
622
|
static createBrokenReference(name, project) {
|
|
478
623
|
return new ReferenceType(name, -1, project);
|
|
479
624
|
}
|
|
480
|
-
|
|
625
|
+
getTypeString() {
|
|
481
626
|
const name = this.reflection ? this.reflection.name : this.name;
|
|
482
627
|
let typeArgs = "";
|
|
483
628
|
if (this.typeArguments && this.typeArguments.length > 0) {
|
|
484
629
|
typeArgs += "<";
|
|
485
630
|
typeArgs += this.typeArguments
|
|
486
|
-
.map((arg) => arg.
|
|
631
|
+
.map((arg) => arg.stringify(exports.TypeContext.referenceTypeArgument))
|
|
487
632
|
.join(", ");
|
|
488
633
|
typeArgs += ">";
|
|
489
634
|
}
|
|
490
635
|
return name + typeArgs;
|
|
491
636
|
}
|
|
637
|
+
needsParenthesis() {
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
492
640
|
}
|
|
493
641
|
exports.ReferenceType = ReferenceType;
|
|
494
642
|
/**
|
|
@@ -507,7 +655,10 @@ class ReflectionType extends Type {
|
|
|
507
655
|
this.type = "reflection";
|
|
508
656
|
this.declaration = declaration;
|
|
509
657
|
}
|
|
510
|
-
|
|
658
|
+
// This really ought to do better, but I'm putting off investing effort here until
|
|
659
|
+
// I'm fully convinced that keeping this is a good idea. Currently, I'd much rather
|
|
660
|
+
// change object types to not create reflections.
|
|
661
|
+
getTypeString() {
|
|
511
662
|
if (!this.declaration.children && this.declaration.signatures) {
|
|
512
663
|
return "Function";
|
|
513
664
|
}
|
|
@@ -515,6 +666,9 @@ class ReflectionType extends Type {
|
|
|
515
666
|
return "Object";
|
|
516
667
|
}
|
|
517
668
|
}
|
|
669
|
+
needsParenthesis() {
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
518
672
|
}
|
|
519
673
|
exports.ReflectionType = ReflectionType;
|
|
520
674
|
/**
|
|
@@ -530,8 +684,11 @@ class RestType extends Type {
|
|
|
530
684
|
this.elementType = elementType;
|
|
531
685
|
this.type = "rest";
|
|
532
686
|
}
|
|
533
|
-
|
|
534
|
-
return `...${
|
|
687
|
+
getTypeString() {
|
|
688
|
+
return `...${this.elementType.stringify(exports.TypeContext.restElement)}`;
|
|
689
|
+
}
|
|
690
|
+
needsParenthesis() {
|
|
691
|
+
return false;
|
|
535
692
|
}
|
|
536
693
|
}
|
|
537
694
|
exports.RestType = RestType;
|
|
@@ -548,16 +705,22 @@ class TemplateLiteralType extends Type {
|
|
|
548
705
|
this.tail = tail;
|
|
549
706
|
this.type = "template-literal";
|
|
550
707
|
}
|
|
551
|
-
|
|
708
|
+
getTypeString() {
|
|
552
709
|
return [
|
|
553
710
|
"`",
|
|
554
711
|
this.head,
|
|
555
712
|
...this.tail.map(([type, text]) => {
|
|
556
|
-
return "${" +
|
|
713
|
+
return ("${" +
|
|
714
|
+
type.stringify(exports.TypeContext.templateLiteralElement) +
|
|
715
|
+
"}" +
|
|
716
|
+
text);
|
|
557
717
|
}),
|
|
558
718
|
"`",
|
|
559
719
|
].join("");
|
|
560
720
|
}
|
|
721
|
+
needsParenthesis() {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
561
724
|
}
|
|
562
725
|
exports.TemplateLiteralType = TemplateLiteralType;
|
|
563
726
|
/**
|
|
@@ -573,8 +736,15 @@ class TupleType extends Type {
|
|
|
573
736
|
this.type = "tuple";
|
|
574
737
|
this.elements = elements;
|
|
575
738
|
}
|
|
576
|
-
|
|
577
|
-
return "[" +
|
|
739
|
+
getTypeString() {
|
|
740
|
+
return ("[" +
|
|
741
|
+
this.elements
|
|
742
|
+
.map((t) => t.stringify(exports.TypeContext.tupleElement))
|
|
743
|
+
.join(", ") +
|
|
744
|
+
"]");
|
|
745
|
+
}
|
|
746
|
+
needsParenthesis() {
|
|
747
|
+
return false;
|
|
578
748
|
}
|
|
579
749
|
}
|
|
580
750
|
exports.TupleType = TupleType;
|
|
@@ -596,8 +766,11 @@ class NamedTupleMember extends Type {
|
|
|
596
766
|
/**
|
|
597
767
|
* Return a string representation of this type.
|
|
598
768
|
*/
|
|
599
|
-
|
|
600
|
-
return `${this.name}${this.isOptional ? "?" : ""}: ${this.element}`;
|
|
769
|
+
getTypeString() {
|
|
770
|
+
return `${this.name}${this.isOptional ? "?" : ""}: ${this.element.stringify(exports.TypeContext.tupleElement)}`;
|
|
771
|
+
}
|
|
772
|
+
needsParenthesis() {
|
|
773
|
+
return false;
|
|
601
774
|
}
|
|
602
775
|
}
|
|
603
776
|
exports.NamedTupleMember = NamedTupleMember;
|
|
@@ -616,8 +789,36 @@ class TypeOperatorType extends Type {
|
|
|
616
789
|
this.operator = operator;
|
|
617
790
|
this.type = "typeOperator";
|
|
618
791
|
}
|
|
619
|
-
|
|
620
|
-
return `${this.operator} ${this.target.
|
|
792
|
+
getTypeString() {
|
|
793
|
+
return `${this.operator} ${this.target.stringify(exports.TypeContext.typeOperatorTarget)}`;
|
|
794
|
+
}
|
|
795
|
+
needsParenthesis(context) {
|
|
796
|
+
const map = {
|
|
797
|
+
none: false,
|
|
798
|
+
templateLiteralElement: false,
|
|
799
|
+
arrayElement: true,
|
|
800
|
+
indexedAccessElement: false,
|
|
801
|
+
conditionalCheck: false,
|
|
802
|
+
conditionalExtends: false,
|
|
803
|
+
conditionalTrue: false,
|
|
804
|
+
conditionalFalse: false,
|
|
805
|
+
indexedIndex: false,
|
|
806
|
+
indexedObject: true,
|
|
807
|
+
inferredConstraint: false,
|
|
808
|
+
intersectionElement: false,
|
|
809
|
+
mappedName: false,
|
|
810
|
+
mappedParameter: false,
|
|
811
|
+
mappedTemplate: false,
|
|
812
|
+
optionalElement: true,
|
|
813
|
+
predicateTarget: false,
|
|
814
|
+
queryTypeTarget: false,
|
|
815
|
+
typeOperatorTarget: false,
|
|
816
|
+
referenceTypeArgument: false,
|
|
817
|
+
restElement: false,
|
|
818
|
+
tupleElement: false,
|
|
819
|
+
unionElement: false,
|
|
820
|
+
};
|
|
821
|
+
return map[context];
|
|
621
822
|
}
|
|
622
823
|
}
|
|
623
824
|
exports.TypeOperatorType = TypeOperatorType;
|
|
@@ -635,12 +836,53 @@ class UnionType extends Type {
|
|
|
635
836
|
this.type = "union";
|
|
636
837
|
this.normalize();
|
|
637
838
|
}
|
|
638
|
-
|
|
639
|
-
return this.types
|
|
839
|
+
getTypeString() {
|
|
840
|
+
return this.types
|
|
841
|
+
.map((t) => t.stringify(exports.TypeContext.unionElement))
|
|
842
|
+
.join(" | ");
|
|
843
|
+
}
|
|
844
|
+
needsParenthesis(context) {
|
|
845
|
+
const map = {
|
|
846
|
+
none: false,
|
|
847
|
+
templateLiteralElement: false,
|
|
848
|
+
arrayElement: true,
|
|
849
|
+
indexedAccessElement: false,
|
|
850
|
+
conditionalCheck: true,
|
|
851
|
+
conditionalExtends: false,
|
|
852
|
+
conditionalTrue: false,
|
|
853
|
+
conditionalFalse: false,
|
|
854
|
+
indexedIndex: false,
|
|
855
|
+
indexedObject: true,
|
|
856
|
+
inferredConstraint: false,
|
|
857
|
+
intersectionElement: true,
|
|
858
|
+
mappedName: false,
|
|
859
|
+
mappedParameter: false,
|
|
860
|
+
mappedTemplate: false,
|
|
861
|
+
optionalElement: true,
|
|
862
|
+
predicateTarget: false,
|
|
863
|
+
queryTypeTarget: false,
|
|
864
|
+
typeOperatorTarget: true,
|
|
865
|
+
referenceTypeArgument: false,
|
|
866
|
+
restElement: false,
|
|
867
|
+
tupleElement: false,
|
|
868
|
+
unionElement: false,
|
|
869
|
+
};
|
|
870
|
+
return map[context];
|
|
640
871
|
}
|
|
641
872
|
normalize() {
|
|
642
|
-
|
|
643
|
-
|
|
873
|
+
let trueIndex = -1;
|
|
874
|
+
let falseIndex = -1;
|
|
875
|
+
for (let i = 0; i < this.types.length && (trueIndex === -1 || falseIndex === -1); i++) {
|
|
876
|
+
const t = this.types[i];
|
|
877
|
+
if (t instanceof LiteralType) {
|
|
878
|
+
if (t.value === true) {
|
|
879
|
+
trueIndex = i;
|
|
880
|
+
}
|
|
881
|
+
if (t.value === false) {
|
|
882
|
+
falseIndex = i;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
644
886
|
if (trueIndex !== -1 && falseIndex !== -1) {
|
|
645
887
|
this.types.splice(Math.max(trueIndex, falseIndex), 1);
|
|
646
888
|
this.types.splice(Math.min(trueIndex, falseIndex), 1, new IntrinsicType("boolean"));
|
|
@@ -657,8 +899,15 @@ class UnknownType extends Type {
|
|
|
657
899
|
this.type = "unknown";
|
|
658
900
|
this.name = name;
|
|
659
901
|
}
|
|
660
|
-
|
|
902
|
+
getTypeString() {
|
|
661
903
|
return this.name;
|
|
662
904
|
}
|
|
905
|
+
/**
|
|
906
|
+
* Always returns true if not at the root level, we have no idea what's in here, so wrap it in parenthesis
|
|
907
|
+
* to be extra safe.
|
|
908
|
+
*/
|
|
909
|
+
needsParenthesis(context) {
|
|
910
|
+
return context !== exports.TypeContext.none;
|
|
911
|
+
}
|
|
663
912
|
}
|
|
664
913
|
exports.UnknownType = UnknownType;
|