docs: fix empty return in references (#11343)

This commit is contained in:
Shahed Nasser
2025-02-06 14:35:45 +02:00
committed by GitHub
parent 0aa84fc371
commit ccb332ce41
8 changed files with 40 additions and 32 deletions
@@ -10,13 +10,22 @@ export default function (theme: MarkdownTheme) {
Handlebars.registerHelper(
"returns",
function (reflection: SignatureReflection) {
let returnContent = ""
if (reflection.variant === "signature" && "type" in reflection) {
return getReturnFromType(theme, reflection)
returnContent = getReturnFromType(theme, reflection)
} else if (reflection.comment) {
return getReturnFromComment(theme, reflection.comment, reflection.name)
} else {
returnContent = getReturnFromComment(
theme,
reflection.comment,
reflection.name
)
}
if (!returnContent.length) {
return ""
}
return `${Handlebars.helpers.titleLevel()} Returns\n\n${returnContent}`
}
)
}
@@ -44,6 +53,10 @@ function getReturnFromType(
maxLevel,
})
if (!componentItems.length) {
return ""
}
if (parameterStyle === "component") {
return formatParameterComponent({
parameterComponent,
@@ -68,12 +68,12 @@
{{#if type}}
{{{titleLevel}}} Returns
{{#if (sectionEnabled "member_signature_returns")}}
{{#with type}}
{{{titleLevel}}} Returns
{{{type 'all'}}}
{{/with}}
@@ -280,12 +280,27 @@ export function loadComment(
return ""
}
const emptyValues = ["void", "never", "undefined"]
export function isEmpty(reflectionTypes: SomeType[]) {
return reflectionTypes.every(
(type) =>
type.type === "intrinsic" &&
(type.name === "void" ||
type.name === "never" ||
type.name === "undefined")
)
return reflectionTypes.every((type) => {
if (type.type === "intrinsic" && emptyValues.includes(type.name)) {
return true
}
if (type.type !== "union") {
return false
}
return type.types.every((unionType) => {
if (
unionType.type === "intrinsic" &&
emptyValues.includes(unionType.name)
) {
return true
}
return false
})
})
}