Skip to content

Commit

Permalink
fix(core): expose "@return" block tags on declarations (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Oct 1, 2024
1 parent 63aae5b commit 300db20
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/orange-horses-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': patch
---

- Expose "@return" block tags on declarations (#694)
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export function comment(
headingLevel?: number;
showSummary?: boolean;
showTags?: boolean;
showReturns?: boolean;
isTableColumn?: boolean;
} = {},
) {
const opts = {
headingLevel: undefined,
showSummary: true,
showTags: true,
showReturns: false,
isTableColumn: false,
...options,
};
Expand Down Expand Up @@ -83,7 +85,7 @@ export function comment(
[],
);

const filteredBlockTags = ['@returns'];
const filteredBlockTags = opts.showReturns ? [] : ['@returns'];

const tags = blockTags
.filter((tag) => !filteredBlockTags.includes(tag.tag))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export function declaration(
headingLevel: opts.headingLevel,
showSummary: false,
showTags: true,
showReturns: true,
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const resourcePartials = (context: MarkdownThemeContext) => {
headingLevel?: number | undefined;
showSummary?: boolean | undefined;
showTags?: boolean | undefined;
showReturns?: boolean | undefined;
isTableColumn?: boolean | undefined;
} = {},
) => partials.comment.apply(context, [model, options]) as string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,11 @@ export type __TypeDeclarationWithSpecialCharacters_<T, U> = {
'|prop|with|pipes|': '|prop|with|pipes|';
'`prop`with`backticks`': '`prop`with`backticks`';
};

/**
* Comments for TypeWithReturns
*
* @returns
* - return comments.
*/
export type TypeWithReturns = string;
Original file line number Diff line number Diff line change
Expand Up @@ -4486,6 +4486,11 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output
"kind": 2097152,
"path": "type-aliases/TypeWithExternalSymbolLinkMapping.md"
},
{
"title": "TypeWithReturns",
"kind": 2097152,
"path": "type-aliases/TypeWithReturns.md"
},
{
"title": "TypeWithTypeParams",
"kind": 2097152,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Module commments
| [StringLiteralType](type-aliases/StringLiteralType.md) | Comments for StringLiteralType |
| [TupleType](type-aliases/TupleType.md) | Comments for TupleType |
| [TypeWithExternalSymbolLinkMapping](type-aliases/TypeWithExternalSymbolLinkMapping.md) | Comments for TypeWithExternalSymbolLinkMapping |
| [TypeWithReturns](type-aliases/TypeWithReturns.md) | Comments for TypeWithReturns |
| [TypeWithTypeParams](type-aliases/TypeWithTypeParams.md) | Comments for TypeWithTypeParams |
| [UnionType](type-aliases/UnionType.md) | Comments for UnionType |
| [UnionTypeWithTemplateStrings](type-aliases/UnionTypeWithTemplateStrings.md) | Union with template strings |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,42 @@ Comments for TypeWithTypeParams
"
`;
exports[`Type Alias Reflection should compile type with returns: (Output File Strategy "members") (Option Group "1") 1`] = `
"# Type Alias: TypeWithReturns
> **TypeWithReturns**: \`string\`
Comments for TypeWithReturns
## Returns
- return comments.
## Source
[types.ts:1](http://source-url)
"
`;
exports[`Type Alias Reflection should compile type with returns: (Output File Strategy "members") (Option Group "2") 1`] = `
"# Type Alias: TypeWithReturns
\`\`\`ts
type TypeWithReturns: string;
\`\`\`
Comments for TypeWithReturns
## Returns
- return comments.
## Source
[types.ts:1](http://source-url)
"
`;
exports[`Type Alias Reflection should compile union type with template strings: (Output File Strategy "members") (Option Group "1") 1`] = `
"# Type Alias: UnionTypeWithTemplateStrings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb
"type-aliases/TupleType.md",
"type-aliases/TypeDeclarationWithSpecialCharacters.md",
"type-aliases/TypeWithExternalSymbolLinkMapping.md",
"type-aliases/TypeWithReturns.md",
"type-aliases/TypeWithTypeParams.md",
"type-aliases/UnionType.md",
"type-aliases/UnionTypeWithTemplateStrings.md",
Expand Down Expand Up @@ -923,6 +924,7 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb
"type-aliases/TupleType.md",
"type-aliases/TypeDeclarationWithSpecialCharacters.md",
"type-aliases/TypeWithExternalSymbolLinkMapping.md",
"type-aliases/TypeWithReturns.md",
"type-aliases/TypeWithTypeParams.md",
"type-aliases/UnionType.md",
"type-aliases/UnionTypeWithTemplateStrings.md",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,12 @@ describe(`Type Alias Reflection`, () => {
'type-aliases/UnionTypeWithTemplateStrings.md',
);
});

test(`should compile type with returns`, () => {
expectFileToEqual(
'reflections',
'members',
'type-aliases/TypeWithReturns.md',
);
});
});

0 comments on commit 300db20

Please sign in to comment.