Skip to content

Commit

Permalink
fix(core): correctly display inline objects for tuple optional types
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Dec 31, 2024
1 parent ed1f3e9 commit e8a181c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-rules-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': patch
---

- Correctly display inline objects for tuple optional types (#745).
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { OptionalType } from 'typedoc';
export function optionalType(
this: MarkdownThemeContext,
model: OptionalType,
options?: { forceCollapse?: boolean },
): string {
const result = this.partials.someType(model.elementType);
const result = this.partials.someType(model.elementType, {
forceCollapse: options?.forceCollapse,
});
return model.elementType.type === 'union' ? `(${result})?` : `${result}?`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export function someType(
}

if (model instanceof OptionalType) {
return this.partials.optionalType(model);
return this.partials.optionalType(model, {
forceCollapse: options?.forceCollapse,
});
}

if (model.toString() == 'null') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ There is no association list partial for properties as these are handled as a st
partials.literalType.apply(context, [model]) as string,
namedTupleType: (model: NamedTupleMember) =>
partials.namedTupleType.apply(context, [model]) as string,
optionalType: (model: OptionalType) =>
partials.optionalType.apply(context, [model]) as string,
optionalType: (
model: OptionalType,
options?: { forceCollapse?: boolean | undefined } | undefined,
) => partials.optionalType.apply(context, [model, options]) as string,
queryType: (model: QueryType) =>
partials.queryType.apply(context, [model]) as string,
referenceType: (model: ReferenceType) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"declaration": true,
"lib": ["es2022", "dom"],
"module": "node16",
"strict": true,
"strict": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"target": "es2022"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Comments for array of union stuff
### a
\\[(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?\\]
\\[[\`Stuff\`](../type-aliases/Stuff.md)?\\]
## Returns
Expand All @@ -523,7 +523,7 @@ exports[`Function Reflection should compile function with array of union stuff:
"# Function: functionWithArrayOfUnionStuff()
\`\`\`ts
function functionWithArrayOfUnionStuff(a: [(null | Stuff)?]): void
function functionWithArrayOfUnionStuff(a: [Stuff?]): void
\`\`\`
Defined in: [functions.ts:1](http://source-url)
Expand All @@ -534,7 +534,7 @@ Comments for array of union stuff
| Parameter | Type |
| :------ | :------ |
| \`a\` | \\[(\`null\` \\| [\`Stuff\`](../type-aliases/Stuff.md))?\\] |
| \`a\` | \\[[\`Stuff\`](../type-aliases/Stuff.md)?\\] |
## Returns
Expand Down Expand Up @@ -1170,7 +1170,7 @@ Defined in: [functions.ts:1](http://source-url)
### opts
\\[(\`null\` \\| \\{ \`a\`: \`string\`; \`b\`: \`string\`; \\})?\\]
\\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}?\\]
## Returns
Expand All @@ -1182,12 +1182,10 @@ exports[`Function Reflection should compile function with tuple type optional pa
"# Function: tupleTypeFunctionOptional()
\`\`\`ts
function tupleTypeFunctionOptional(opts: [(
| null
| {
function tupleTypeFunctionOptional(opts: [{
a: string;
b: string;
})?]): void
}?]): void
\`\`\`
Defined in: [functions.ts:1](http://source-url)
Expand All @@ -1196,7 +1194,7 @@ Defined in: [functions.ts:1](http://source-url)
| Parameter | Type |
| :------ | :------ |
| \`opts\` | \\[( \\| \`null\` \\| \\{ \`a\`: \`string\`; \`b\`: \`string\`; \\})?\\] |
| \`opts\` | \\[\\{ \`a\`: \`string\`; \`b\`: \`string\`; \\}?\\] |
## Returns
Expand Down Expand Up @@ -1299,7 +1297,7 @@ Function with type parameters
exports[`Function Reflection should compile function with union params: (Output File Strategy "members") (Option Group "1") 1`] = `
"# Function: functionWithUnionParams()
> **functionWithUnionParams**(\`primitiveUnions\`, \`objectUnions\`, \`mixedUnions\`, \`noUnions\`): \`undefined\`
> **functionWithUnionParams**(\`primitiveUnions\`, \`objectUnions\`, \`mixedUnions\`, \`noUnions\`): \`any\`
Defined in: [functions.ts:1](http://source-url)
Expand Down Expand Up @@ -1367,7 +1365,7 @@ Comments for noUnions
## Returns
\`undefined\`
\`any\`
"
`;
Expand Down Expand Up @@ -1402,7 +1400,7 @@ function functionWithUnionParams(
z: string;
};
},
noUnions: string): undefined
noUnions: string): any
\`\`\`
Defined in: [functions.ts:1](http://source-url)
Expand All @@ -1418,6 +1416,6 @@ Defined in: [functions.ts:1](http://source-url)
## Returns
\`undefined\`
\`any\`
"
`;

0 comments on commit e8a181c

Please sign in to comment.