docs: fix empty return in references (#11343)
This commit is contained in:
@@ -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,
|
||||
|
||||
+2
-2
@@ -68,12 +68,12 @@
|
||||
|
||||
{{#if type}}
|
||||
|
||||
{{{titleLevel}}} Returns
|
||||
|
||||
{{#if (sectionEnabled "member_signature_returns")}}
|
||||
|
||||
{{#with type}}
|
||||
|
||||
{{{titleLevel}}} Returns
|
||||
|
||||
{{{type 'all'}}}
|
||||
|
||||
{{/with}}
|
||||
|
||||
+22
-7
@@ -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
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user