Skip to content

Commit 64a2a4f

Browse files
committed
fix: Add test for {} and fix generation
1 parent 0209789 commit 64a2a4f

File tree

7 files changed

+29
-18
lines changed

7 files changed

+29
-18
lines changed

examples/basic/src/flattened.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ class FlattenedClass {
99
* @param options.anotherValue Another value on the options object parameter.
1010
* @param options.moreOptions A typed child object of the options object.
1111
* @param options.moreOptions.moreValues A value of the typed child object.
12+
* @param options.emptyObject An empty object
1213
*/
1314
options: {
1415
value?: string;
1516
anotherValue?: string;
1617
moreOptions?: {
1718
moreValues: number;
1819
};
20+
emptyObject: {}
1921
};
2022

2123
/**

src/lib/converter/types/reference.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ReferenceConverter extends ConverterTypeComponent implements TypeNo
4747
convertNode(context: Context, node: ts.TypeReferenceNode, type: ts.TypeReference): Type | undefined {
4848
if (!type.symbol) {
4949
return new IntrinsicType('Object');
50-
} else if (type.symbol.declarations && (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral)) {
50+
} else if (type.symbol.flags & (ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.ObjectLiteral)) {
5151
return this.convertLiteral(context, type.symbol, node);
5252
}
5353

@@ -76,7 +76,7 @@ export class ReferenceConverter extends ConverterTypeComponent implements TypeNo
7676
convertType(context: Context, type: ts.TypeReference): Type | undefined {
7777
if (!type.symbol) {
7878
return new IntrinsicType('Object');
79-
} else if (type.symbol.declarations && (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral)) {
79+
} else if (type.symbol.flags & (ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.ObjectLiteral)) {
8080
return this.convertLiteral(context, type.symbol);
8181
}
8282

@@ -111,7 +111,8 @@ export class ReferenceConverter extends ConverterTypeComponent implements TypeNo
111111
* @returns A type reflection representing the given type literal.
112112
*/
113113
private convertLiteral(context: Context, symbol: ts.Symbol, node?: ts.Node): Type | undefined {
114-
for (const declaration of symbol.declarations) {
114+
// The TS types lie. symbol.declarations is undefined for the type {}
115+
for (const declaration of symbol.declarations ?? []) {
115116
if (context.visitStack.includes(declaration)) {
116117
if (declaration.kind === ts.SyntaxKind.TypeLiteral ||
117118
declaration.kind === ts.SyntaxKind.ObjectLiteralExpression) {
@@ -128,7 +129,7 @@ export class ReferenceConverter extends ConverterTypeComponent implements TypeNo
128129
context.registerReflection(declaration, symbol);
129130
context.trigger(Converter.EVENT_CREATE_DECLARATION, declaration, node);
130131
context.withScope(declaration, () => {
131-
symbol.declarations.forEach((node) => {
132+
(symbol.declarations ?? []).forEach((node) => {
132133
this.owner.convertNode(context, node);
133134
});
134135
});

src/test/renderer/specs/classes/_flattened_.flattenedclass.html

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ <h3>constructor</h3>
120120
<li class="tsd-description">
121121
<aside class="tsd-sources">
122122
<ul>
123-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L66">flattened.ts:66</a></li>
123+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L68">flattened.ts:68</a></li>
124124
</ul>
125125
</aside>
126126
<div class="tsd-comment tsd-typography">
@@ -180,7 +180,7 @@ <h3>callback</h3>
180180
<div class="tsd-signature tsd-kind-icon">callback<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span>param<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span>, optionalParam<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">string</span></div>
181181
<aside class="tsd-sources">
182182
<ul>
183-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L27">flattened.ts:27</a></li>
183+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L29">flattened.ts:29</a></li>
184184
</ul>
185185
</aside>
186186
<div class="tsd-comment tsd-typography">
@@ -225,7 +225,7 @@ <h3>indexed</h3>
225225
<div class="tsd-signature tsd-kind-icon">indexed<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>test<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span></div>
226226
<aside class="tsd-sources">
227227
<ul>
228-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L35">flattened.ts:35</a></li>
228+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L37">flattened.ts:37</a></li>
229229
</ul>
230230
</aside>
231231
<div class="tsd-comment tsd-typography">
@@ -262,7 +262,7 @@ <h3>multiple<wbr>Call<wbr>Signatures</h3>
262262
<div class="tsd-signature tsd-kind-icon">multiple<wbr>Call<wbr>Signatures<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span><span class="tsd-signature-symbol">(</span>value<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="_flattened_.flattenedclass.html" class="tsd-signature-type">FlattenedClass</a><span class="tsd-signature-symbol"> }</span></div>
263263
<aside class="tsd-sources">
264264
<ul>
265-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L44">flattened.ts:44</a></li>
265+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L46">flattened.ts:46</a></li>
266266
</ul>
267267
</aside>
268268
<div class="tsd-comment tsd-typography">
@@ -319,10 +319,10 @@ <h4 class="tsd-returns-title">Returns <a href="_flattened_.flattenedclass.html"
319319
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
320320
<a name="options" class="tsd-anchor"></a>
321321
<h3>options</h3>
322-
<div class="tsd-signature tsd-kind-icon">options<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>anotherValue<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>moreOptions<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-symbol">{ </span>moreValues<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol">; </span>value<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span></div>
322+
<div class="tsd-signature tsd-kind-icon">options<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>anotherValue<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>emptyObject<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">{}</span><span class="tsd-signature-symbol">; </span>moreOptions<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-symbol">{ </span>moreValues<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol">; </span>value<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span></div>
323323
<aside class="tsd-sources">
324324
<ul>
325-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L13">flattened.ts:13</a></li>
325+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L14">flattened.ts:14</a></li>
326326
</ul>
327327
</aside>
328328
<div class="tsd-comment tsd-typography">
@@ -339,6 +339,14 @@ <h5><span class="tsd-flag ts-flagOptional">Optional</span> another<wbr>Value<spa
339339
<p>Another value on the options object parameter.</p>
340340
</div>
341341
</li>
342+
<li class="tsd-parameter">
343+
<h5>empty<wbr>Object<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">{}</span></h5>
344+
<div class="tsd-comment tsd-typography">
345+
<p>An empty object</p>
346+
</div>
347+
<ul class="tsd-parameters">
348+
</ul>
349+
</li>
342350
<li class="tsd-parameter">
343351
<h5><span class="tsd-flag ts-flagOptional">Optional</span> more<wbr>Options<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-symbol">{ </span>moreValues<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> }</span></h5>
344352
<div class="tsd-comment tsd-typography">
@@ -368,7 +376,7 @@ <h3>single<wbr>Call<wbr>Signature</h3>
368376
<div class="tsd-signature tsd-kind-icon">single<wbr>Call<wbr>Signature<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">...</span>args<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">string</span></div>
369377
<aside class="tsd-sources">
370378
<ul>
371-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L61">flattened.ts:61</a></li>
379+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L63">flattened.ts:63</a></li>
372380
</ul>
373381
</aside>
374382
<div class="tsd-comment tsd-typography">
@@ -416,7 +424,7 @@ <h3>union<wbr>And<wbr>Function</h3>
416424
<div class="tsd-signature tsd-kind-icon">union<wbr>And<wbr>Function<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">1</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">2</span></div>
417425
<aside class="tsd-sources">
418426
<ul>
419-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L66">flattened.ts:66</a></li>
427+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L68">flattened.ts:68</a></li>
420428
</ul>
421429
</aside>
422430
<div class="tsd-comment tsd-typography">

src/test/renderer/specs/interfaces/_mixin_.mixin1type.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ <h1>Interface Mixin1Type</h1>
8080
<h3>Hierarchy</h3>
8181
<ul class="tsd-hierarchy">
8282
<li>
83-
<span class="tsd-signature-type">Mixin1Class</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol"> &amp; </span><a href="../classes/_mixin_.base.html" class="tsd-signature-type">Base</a>
83+
<span class="tsd-signature-type">Mixin1Class</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-symbol">{}</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol"> &amp; </span><a href="../classes/_mixin_.base.html" class="tsd-signature-type">Base</a>
8484
<ul class="tsd-hierarchy">
8585
<li>
8686
<span class="target">Mixin1Type</span>

src/test/renderer/specs/interfaces/_mixin_.mixin2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ <h1>Interface Mixin2</h1>
8080
<h3>Hierarchy</h3>
8181
<ul class="tsd-hierarchy">
8282
<li>
83-
<span class="tsd-signature-type">Mixin2</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol"> &amp; </span><a href="_mixin_.mixin1type.html" class="tsd-signature-type">Mixin1Type</a><span class="tsd-signature-symbol"> &amp; </span><a href="../classes/_mixin_.base.html" class="tsd-signature-type">Base</a>
83+
<span class="tsd-signature-type">Mixin2</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-symbol">{}</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol"> &amp; </span><a href="_mixin_.mixin1type.html" class="tsd-signature-type">Mixin1Type</a><span class="tsd-signature-symbol"> &amp; </span><a href="../classes/_mixin_.base.html" class="tsd-signature-type">Base</a>
8484
<ul class="tsd-hierarchy">
8585
<li>
8686
<span class="target">Mixin2</span>

src/test/renderer/specs/modules/_flattened_.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ <h3>flattened<wbr>Callback</h3>
9999
<li class="tsd-description">
100100
<aside class="tsd-sources">
101101
<ul>
102-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L93">flattened.ts:93</a></li>
102+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L95">flattened.ts:95</a></li>
103103
</ul>
104104
</aside>
105105
<div class="tsd-comment tsd-typography">
@@ -157,7 +157,7 @@ <h3>flattened<wbr>Index<wbr>Signature</h3>
157157
<li class="tsd-description">
158158
<aside class="tsd-sources">
159159
<ul>
160-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L120">flattened.ts:120</a></li>
160+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L122">flattened.ts:122</a></li>
161161
</ul>
162162
</aside>
163163
<div class="tsd-comment tsd-typography">
@@ -207,7 +207,7 @@ <h3>flattened<wbr>Parameter</h3>
207207
<li class="tsd-description">
208208
<aside class="tsd-sources">
209209
<ul>
210-
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L104">flattened.ts:104</a></li>
210+
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/flattened.ts#L106">flattened.ts:106</a></li>
211211
</ul>
212212
</aside>
213213
<div class="tsd-comment tsd-typography">

src/test/renderer/specs/modules/_generics_.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ <h2>Type aliases</h2>
102102
<section class="tsd-panel tsd-member tsd-kind-type-alias tsd-parent-kind-external-module tsd-has-type-parameter">
103103
<a name="horriblerecursivetypethatshouldnotbeusedbyanyone" class="tsd-anchor"></a>
104104
<h3>Horrible<wbr>Recursive<wbr>Type<wbr>That<wbr>Should<wbr>Not<wbr>BeUsed<wbr>ByAnyone</h3>
105-
<div class="tsd-signature tsd-kind-icon">Horrible<wbr>Recursive<wbr>Type<wbr>That<wbr>Should<wbr>Not<wbr>BeUsed<wbr>ByAnyone&lt;T, R&gt;<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>0<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">R</span><span class="tsd-signature-symbol">; </span>1<span class="tsd-signature-symbol">: </span><a href="_generics_.html#horriblerecursivetypethatshouldnotbeusedbyanyone" class="tsd-signature-type">HorribleRecursiveTypeThatShouldNotBeUsedByAnyone</a><span class="tsd-signature-symbol">&lt;</span><a href="_generics_.html#popfront" class="tsd-signature-type">PopFront</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol">[</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">[</span><span class="tsd-signature-type">"length"</span><span class="tsd-signature-symbol">]</span><span class="tsd-signature-symbol"> extends </span><span class="tsd-signature-type">0</span><span class="tsd-signature-symbol"> ? </span><span class="tsd-signature-type">0</span><span class="tsd-signature-symbol"> : </span><span class="tsd-signature-type">1</span><span class="tsd-signature-symbol">]</span></div>
105+
<div class="tsd-signature tsd-kind-icon">Horrible<wbr>Recursive<wbr>Type<wbr>That<wbr>Should<wbr>Not<wbr>BeUsed<wbr>ByAnyone&lt;T, R&gt;<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>0<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">R</span><span class="tsd-signature-symbol">; </span>1<span class="tsd-signature-symbol">: </span><a href="_generics_.html#horriblerecursivetypethatshouldnotbeusedbyanyone" class="tsd-signature-type">HorribleRecursiveTypeThatShouldNotBeUsedByAnyone</a><span class="tsd-signature-symbol">&lt;</span><a href="_generics_.html#popfront" class="tsd-signature-type">PopFront</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-symbol">{}</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol">[</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">[</span><span class="tsd-signature-type">"length"</span><span class="tsd-signature-symbol">]</span><span class="tsd-signature-symbol"> extends </span><span class="tsd-signature-type">0</span><span class="tsd-signature-symbol"> ? </span><span class="tsd-signature-type">0</span><span class="tsd-signature-symbol"> : </span><span class="tsd-signature-type">1</span><span class="tsd-signature-symbol">]</span></div>
106106
<aside class="tsd-sources">
107107
<ul>
108108
<li>Defined in <a href="https://github.com/sebastian-lenz/typedoc/blob/master/examples/basic/src/generics.ts#L84">generics.ts:84</a></li>

0 commit comments

Comments
 (0)