Skip to content

Commit 09f6e97

Browse files
committed
fix(core): always display inline object for tuple type
1 parent 81dbb4a commit 09f6e97

File tree

9 files changed

+268
-11
lines changed

9 files changed

+268
-11
lines changed

.changeset/eleven-boats-give.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-markdown': patch
3+
---
4+
5+
- Always display inline object for tuple types (#745).

packages/typedoc-plugin-markdown/src/theme/context/partials/type.tuple.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function tupleType(
55
this: MarkdownThemeContext,
66
model: TupleType,
77
): string {
8-
return `[${model.elements
9-
.map((element) => this.partials.someType(element))
10-
.join(', ')}]`;
8+
return `\\[${model.elements
9+
.map((element) => this.partials.someType(element, { forceCollapse: true }))
10+
.join(', ')}\\]`;
1111
}

packages/typedoc-plugin-markdown/test/fixtures/src/reflections/functions.ts

+35
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,38 @@ export const functionWithArrayOfUnionStuff = (
280280
* Comments for array of stuff?
281281
*/
282282
export const functionWithArrayOfOptionalStuff = (a: [Stuff?]) => {};
283+
284+
export const typedef = {
285+
/**
286+
* Comments for a
287+
*/
288+
a: '',
289+
b: '',
290+
};
291+
292+
/**
293+
* @inline
294+
*/
295+
export type TypeDefOptions = typeof typedef;
296+
297+
/**
298+
* @inline
299+
*/
300+
export type ExplicitTypeDefOptions = {
301+
a: string;
302+
b: string;
303+
};
304+
305+
export const tupleTypeFunction = (
306+
/**
307+
* opts comments
308+
*/
309+
opts: [TypeDefOptions],
310+
) => {};
311+
export const tupleTypeFunctionOptional = (
312+
opts: [(TypeDefOptions | null | undefined)?],
313+
) => {};
314+
315+
export const tupleTypeFunctionInlineExplicit = (
316+
opts: [ExplicitTypeDefOptions],
317+
) => {};

packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap

+30
Original file line numberDiff line numberDiff line change
@@ -4421,6 +4421,11 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output
44214421
"kind": 2097152,
44224422
"path": "type-aliases/ConditionalType.md"
44234423
},
4424+
{
4425+
"title": "ExplicitTypeDefOptions",
4426+
"kind": 2097152,
4427+
"path": "type-aliases/ExplicitTypeDefOptions.md"
4428+
},
44244429
{
44254430
"title": "ExternalReferenceType",
44264431
"kind": 2097152,
@@ -4491,6 +4496,11 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output
44914496
"kind": 2097152,
44924497
"path": "type-aliases/TupleType.md"
44934498
},
4499+
{
4500+
"title": "TypeDefOptions",
4501+
"kind": 2097152,
4502+
"path": "type-aliases/TypeDefOptions.md"
4503+
},
44944504
{
44954505
"title": "TypeWithExternalSymbolLinkMapping",
44964506
"kind": 2097152,
@@ -4551,6 +4561,11 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output
45514561
"kind": 32,
45524562
"path": "variables/templateVariableString.md"
45534563
},
4564+
{
4565+
"title": "typedef",
4566+
"kind": 32,
4567+
"path": "variables/typedef.md"
4568+
},
45544569
{
45554570
"title": "typeOperatorVariable",
45564571
"kind": 32,
@@ -4660,6 +4675,21 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output
46604675
"title": "functionWithUnionParams",
46614676
"kind": 64,
46624677
"path": "functions/functionWithUnionParams.md"
4678+
},
4679+
{
4680+
"title": "tupleTypeFunction",
4681+
"kind": 64,
4682+
"path": "functions/tupleTypeFunction.md"
4683+
},
4684+
{
4685+
"title": "tupleTypeFunctionInlineExplicit",
4686+
"kind": 64,
4687+
"path": "functions/tupleTypeFunctionInlineExplicit.md"
4688+
},
4689+
{
4690+
"title": "tupleTypeFunctionOptional",
4691+
"kind": 64,
4692+
"path": "functions/tupleTypeFunctionOptional.md"
46634693
}
46644694
]
46654695
}

packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.function.spec.ts.snap

+151-6
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ Comments for array of stuff?
453453
454454
### a
455455
456-
[[\`Stuff\`](../type-aliases/Stuff.md)?]
456+
\\[[\`Stuff\`](../type-aliases/Stuff.md)?\\]
457457
458458
## Returns
459459
@@ -478,7 +478,7 @@ Comments for array of stuff?
478478
479479
| Parameter | Type |
480480
| :------ | :------ |
481-
| \`a\` | [[\`Stuff\`](../type-aliases/Stuff.md)?] |
481+
| \`a\` | \\[[\`Stuff\`](../type-aliases/Stuff.md)?\\] |
482482
483483
## Returns
484484
@@ -501,7 +501,7 @@ Comments for array of stuff
501501
502502
### a
503503
504-
[[\`Stuff\`](../type-aliases/Stuff.md)]
504+
\\[[\`Stuff\`](../type-aliases/Stuff.md)\\]
505505
506506
## Returns
507507
@@ -526,7 +526,7 @@ Comments for array of stuff
526526
527527
| Parameter | Type |
528528
| :------ | :------ |
529-
| \`a\` | [[\`Stuff\`](../type-aliases/Stuff.md)] |
529+
| \`a\` | \\[[\`Stuff\`](../type-aliases/Stuff.md)\\] |
530530
531531
## Returns
532532
@@ -549,7 +549,7 @@ Comments for array of union stuff
549549
550550
### a
551551
552-
[(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?]
552+
\\[(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?\\]
553553
554554
## Returns
555555
@@ -574,7 +574,7 @@ Comments for array of union stuff
574574
575575
| Parameter | Type |
576576
| :------ | :------ |
577-
| \`a\` | [(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?] |
577+
| \`a\` | \\[(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?\\] |
578578
579579
## Returns
580580
@@ -731,6 +731,53 @@ This is a function with a parameter that has a default value.
731731
"
732732
`;
733733
734+
exports[`Function Reflection should compile function with explicit inline tuple type optional params: (Output File Strategy "members") (Option Group "1") 1`] = `
735+
"# Function: tupleTypeFunctionInlineExplicit()
736+
737+
> **tupleTypeFunctionInlineExplicit**(\`opts\`): \`void\`
738+
739+
## Parameters
740+
741+
### opts
742+
743+
\\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}\\]
744+
745+
## Returns
746+
747+
\`void\`
748+
749+
## Source
750+
751+
[functions.ts:1](http://source-url)
752+
"
753+
`;
754+
755+
exports[`Function Reflection should compile function with explicit inline tuple type optional params: (Output File Strategy "members") (Option Group "2") 1`] = `
756+
"# Function: tupleTypeFunctionInlineExplicit()
757+
758+
\`\`\`ts
759+
function tupleTypeFunctionInlineExplicit(opts: [{
760+
a: string;
761+
b: string;
762+
}]): void
763+
\`\`\`
764+
765+
## Parameters
766+
767+
| Parameter | Type |
768+
| :------ | :------ |
769+
| \`opts\` | \\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}\\] |
770+
771+
## Returns
772+
773+
\`void\`
774+
775+
## Source
776+
777+
[functions.ts:1](http://source-url)
778+
"
779+
`;
780+
734781
exports[`Function Reflection should compile function with multiple signatures: (Output File Strategy "members") (Option Group "1") 1`] = `
735782
"# Function: functionWithMultipleSignatures()
736783
@@ -1196,6 +1243,104 @@ Function with reset parmas
11961243
"
11971244
`;
11981245
1246+
exports[`Function Reflection should compile function with tuple type optional params: (Output File Strategy "members") (Option Group "1") 1`] = `
1247+
"# Function: tupleTypeFunctionOptional()
1248+
1249+
> **tupleTypeFunctionOptional**(\`opts\`): \`void\`
1250+
1251+
## Parameters
1252+
1253+
### opts
1254+
1255+
\\[(\`null\` \\| \\{ \`a\`: \`string\`; \`b\`: \`string\`; \\})?\\]
1256+
1257+
## Returns
1258+
1259+
\`void\`
1260+
1261+
## Source
1262+
1263+
[functions.ts:1](http://source-url)
1264+
"
1265+
`;
1266+
1267+
exports[`Function Reflection should compile function with tuple type optional params: (Output File Strategy "members") (Option Group "2") 1`] = `
1268+
"# Function: tupleTypeFunctionOptional()
1269+
1270+
\`\`\`ts
1271+
function tupleTypeFunctionOptional(opts: [(
1272+
| null
1273+
| {
1274+
a: string;
1275+
b: string;
1276+
})?]): void
1277+
\`\`\`
1278+
1279+
## Parameters
1280+
1281+
| Parameter | Type |
1282+
| :------ | :------ |
1283+
| \`opts\` | \\[( \\| \`null\` \\| \\{ \`a\`: \`string\`; \`b\`: \`string\`; \\})?\\] |
1284+
1285+
## Returns
1286+
1287+
\`void\`
1288+
1289+
## Source
1290+
1291+
[functions.ts:1](http://source-url)
1292+
"
1293+
`;
1294+
1295+
exports[`Function Reflection should compile function with tuple type params: (Output File Strategy "members") (Option Group "1") 1`] = `
1296+
"# Function: tupleTypeFunction()
1297+
1298+
> **tupleTypeFunction**(\`opts\`): \`void\`
1299+
1300+
## Parameters
1301+
1302+
### opts
1303+
1304+
\\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}\\]
1305+
1306+
opts comments
1307+
1308+
## Returns
1309+
1310+
\`void\`
1311+
1312+
## Source
1313+
1314+
[functions.ts:1](http://source-url)
1315+
"
1316+
`;
1317+
1318+
exports[`Function Reflection should compile function with tuple type params: (Output File Strategy "members") (Option Group "2") 1`] = `
1319+
"# Function: tupleTypeFunction()
1320+
1321+
\`\`\`ts
1322+
function tupleTypeFunction(opts: [{
1323+
a: string;
1324+
b: string;
1325+
}]): void
1326+
\`\`\`
1327+
1328+
## Parameters
1329+
1330+
| Parameter | Type | Description |
1331+
| :------ | :------ | :------ |
1332+
| \`opts\` | \\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}\\] | opts comments |
1333+
1334+
## Returns
1335+
1336+
\`void\`
1337+
1338+
## Source
1339+
1340+
[functions.ts:1](http://source-url)
1341+
"
1342+
`;
1343+
11991344
exports[`Function Reflection should compile function with type parameters: (Output File Strategy "members") (Option Group "1") 1`] = `
12001345
"# Function: functionWithTypeParameters()
12011346

packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.index.spec.ts.snap

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Module comments
7474
| [ArrayOfObjectsType](type-aliases/ArrayOfObjectsType.md) | - |
7575
| [ArrayType](type-aliases/ArrayType.md) | Comments for ArrayType |
7676
| [ConditionalType](type-aliases/ConditionalType.md) | Comments for ConditionalType |
77+
| [ExplicitTypeDefOptions](type-aliases/ExplicitTypeDefOptions.md) | - |
7778
| [ExternalReferenceType](type-aliases/ExternalReferenceType.md) | Comments for ExternalReferenceType |
7879
| [FunctionType](type-aliases/FunctionType.md) | Comments for FunctionType |
7980
| [IndexAccessType](type-aliases/IndexAccessType.md) | Comments for IndexAccessType |
@@ -88,6 +89,7 @@ Module comments
8889
| [StringLiteralType](type-aliases/StringLiteralType.md) | Comments for StringLiteralType |
8990
| [Stuff](type-aliases/Stuff.md) | - |
9091
| [TupleType](type-aliases/TupleType.md) | Comments for TupleType |
92+
| [TypeDefOptions](type-aliases/TypeDefOptions.md) | - |
9193
| [TypeWithExternalSymbolLinkMapping](type-aliases/TypeWithExternalSymbolLinkMapping.md) | Comments for TypeWithExternalSymbolLinkMapping |
9294
| [TypeWithReturns](type-aliases/TypeWithReturns.md) | Comments for TypeWithReturns |
9395
| [TypeWithTypeParams](type-aliases/TypeWithTypeParams.md) | Comments for TypeWithTypeParams |
@@ -104,6 +106,7 @@ Module comments
104106
| [someQuery](variables/someQuery.md) | - |
105107
| [stringVariable](variables/stringVariable.md) | A simple string variable |
106108
| [templateVariableString](variables/templateVariableString.md) | A template variable string |
109+
| [typedef](variables/typedef.md) | - |
107110
| [typeOperatorVariable](variables/typeOperatorVariable.md) | Comments for typeOperatorVariable |
108111
109112
## Functions
@@ -130,5 +133,8 @@ Module comments
130133
| [functionWithRestParams](functions/functionWithRestParams.md) | Function with reset parmas |
131134
| [functionWithTypeParameters](functions/functionWithTypeParameters.md) | Function with type parameters |
132135
| [functionWithUnionParams](functions/functionWithUnionParams.md) | - |
136+
| [tupleTypeFunction](functions/tupleTypeFunction.md) | - |
137+
| [tupleTypeFunctionInlineExplicit](functions/tupleTypeFunctionInlineExplicit.md) | - |
138+
| [tupleTypeFunctionOptional](functions/tupleTypeFunctionOptional.md) | - |
133139
"
134140
`;

packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.type-alias.spec.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ Comments for StringLiteralType
646646
exports[`Type Alias Reflection should compile string tuple type: (Output File Strategy "members") (Option Group "1") 1`] = `
647647
"# Type Alias: TupleType
648648
649-
> **TupleType**: [\`string\`, \`number\`]
649+
> **TupleType**: \\[\`string\`, \`number\`\\]
650650
651651
Comments for TupleType
652652
@@ -674,7 +674,7 @@ Comments for TupleType
674674
exports[`Type Alias Reflection should compile type parameter type: (Output File Strategy "members") (Option Group "1") 1`] = `
675675
"# Type Alias: TypeWithTypeParams\\<T, R\\>
676676
677-
> **TypeWithTypeParams**\\<\`T\`, \`R\`\\>: [\`T\`, \`R\`]
677+
> **TypeWithTypeParams**\\<\`T\`, \`R\`\\>: \\[\`T\`, \`R\`\\]
678678
679679
Comments for TypeWithTypeParams
680680

0 commit comments

Comments
 (0)