typedoc-plugin-markdown
Version:
A TypeDoc plugin that generates TypeScript API documentation as Markdown.
20 lines (19 loc) • 672 B
JavaScript
/**
* Whether a type must be wrapped in parentheses when it is the operand of a
* postfix such as `[]` or `?`, so that `(() => void)[]` is not rendered as
* `() => void[]`, which reads as a function returning an array.
*/
export function needsParentheses(type) {
switch (type.type) {
case 'union':
case 'intersection':
case 'conditional':
case 'typeOperator':
return true;
case 'reflection':
// Rendered as a bare function type (see type.reflection.ts).
return (type.declaration?.signatures?.length === 1 && !type.declaration.children);
default:
return false;
}
}