Skip to content

Commit e8a181c

Browse files
committed
fix(core): correctly display inline objects for tuple optional types
1 parent ed1f3e9 commit e8a181c

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

.changeset/great-rules-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-markdown': patch
3+
---
4+
5+
- Correctly display inline objects for tuple optional types (#745).

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { OptionalType } from 'typedoc';
44
export function optionalType(
55
this: MarkdownThemeContext,
66
model: OptionalType,
7+
options?: { forceCollapse?: boolean },
78
): string {
8-
const result = this.partials.someType(model.elementType);
9+
const result = this.partials.someType(model.elementType, {
10+
forceCollapse: options?.forceCollapse,
11+
});
912
return model.elementType.type === 'union' ? `(${result})?` : `${result}?`;
1013
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export function someType(
8787
}
8888

8989
if (model instanceof OptionalType) {
90-
return this.partials.optionalType(model);
90+
return this.partials.optionalType(model, {
91+
forceCollapse: options?.forceCollapse,
92+
});
9193
}
9294

9395
if (model.toString() == 'null') {

packages/typedoc-plugin-markdown/src/theme/context/resources.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ There is no association list partial for properties as these are handled as a st
257257
partials.literalType.apply(context, [model]) as string,
258258
namedTupleType: (model: NamedTupleMember) =>
259259
partials.namedTupleType.apply(context, [model]) as string,
260-
optionalType: (model: OptionalType) =>
261-
partials.optionalType.apply(context, [model]) as string,
260+
optionalType: (
261+
model: OptionalType,
262+
options?: { forceCollapse?: boolean | undefined } | undefined,
263+
) => partials.optionalType.apply(context, [model, options]) as string,
262264
queryType: (model: QueryType) =>
263265
partials.queryType.apply(context, [model]) as string,
264266
referenceType: (model: ReferenceType) =>

packages/typedoc-plugin-markdown/test/fixtures/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"declaration": true,
66
"lib": ["es2022", "dom"],
77
"module": "node16",
8-
"strict": true,
8+
"strict": false,
99
"noUnusedLocals": false,
1010
"noUnusedParameters": false,
1111
"target": "es2022"

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ Comments for array of union stuff
511511
512512
### a
513513
514-
\\[(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?\\]
514+
\\[[\`Stuff\`](../type-aliases/Stuff.md)?\\]
515515
516516
## Returns
517517
@@ -523,7 +523,7 @@ exports[`Function Reflection should compile function with array of union stuff:
523523
"# Function: functionWithArrayOfUnionStuff()
524524
525525
\`\`\`ts
526-
function functionWithArrayOfUnionStuff(a: [(null | Stuff)?]): void
526+
function functionWithArrayOfUnionStuff(a: [Stuff?]): void
527527
\`\`\`
528528
529529
Defined in: [functions.ts:1](http://source-url)
@@ -534,7 +534,7 @@ Comments for array of union stuff
534534
535535
| Parameter | Type |
536536
| :------ | :------ |
537-
| \`a\` | \\[(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?\\] |
537+
| \`a\` | \\[[\`Stuff\`](../type-aliases/Stuff.md)?\\] |
538538
539539
## Returns
540540
@@ -1170,7 +1170,7 @@ Defined in: [functions.ts:1](http://source-url)
11701170
11711171
### opts
11721172
1173-
\\[(\`null\` \\| \\{ \`a\`: \`string\`; \`b\`: \`string\`; \\})?\\]
1173+
\\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}?\\]
11741174
11751175
## Returns
11761176
@@ -1182,12 +1182,10 @@ exports[`Function Reflection should compile function with tuple type optional pa
11821182
"# Function: tupleTypeFunctionOptional()
11831183
11841184
\`\`\`ts
1185-
function tupleTypeFunctionOptional(opts: [(
1186-
| null
1187-
| {
1185+
function tupleTypeFunctionOptional(opts: [{
11881186
a: string;
11891187
b: string;
1190-
})?]): void
1188+
}?]): void
11911189
\`\`\`
11921190
11931191
Defined in: [functions.ts:1](http://source-url)
@@ -1196,7 +1194,7 @@ Defined in: [functions.ts:1](http://source-url)
11961194
11971195
| Parameter | Type |
11981196
| :------ | :------ |
1199-
| \`opts\` | \\[( \\| \`null\` \\| \\{ \`a\`: \`string\`; \`b\`: \`string\`; \\})?\\] |
1197+
| \`opts\` | \\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}?\\] |
12001198
12011199
## Returns
12021200
@@ -1299,7 +1297,7 @@ Function with type parameters
12991297
exports[`Function Reflection should compile function with union params: (Output File Strategy "members") (Option Group "1") 1`] = `
13001298
"# Function: functionWithUnionParams()
13011299
1302-
> **functionWithUnionParams**(\`primitiveUnions\`, \`objectUnions\`, \`mixedUnions\`, \`noUnions\`): \`undefined\`
1300+
> **functionWithUnionParams**(\`primitiveUnions\`, \`objectUnions\`, \`mixedUnions\`, \`noUnions\`): \`any\`
13031301
13041302
Defined in: [functions.ts:1](http://source-url)
13051303
@@ -1367,7 +1365,7 @@ Comments for noUnions
13671365
13681366
## Returns
13691367
1370-
\`undefined\`
1368+
\`any\`
13711369
"
13721370
`;
13731371
@@ -1402,7 +1400,7 @@ function functionWithUnionParams(
14021400
z: string;
14031401
};
14041402
},
1405-
noUnions: string): undefined
1403+
noUnions: string): any
14061404
\`\`\`
14071405
14081406
Defined in: [functions.ts:1](http://source-url)
@@ -1418,6 +1416,6 @@ Defined in: [functions.ts:1](http://source-url)
14181416
14191417
## Returns
14201418
1421-
\`undefined\`
1419+
\`any\`
14221420
"
14231421
`;

0 commit comments

Comments
 (0)