|
1 | | -import type { DeclarationReflection } from "../../../../models/index.js"; |
| 1 | +import type { DeclarationReflection } from "#models"; |
2 | 2 | import { JSX } from "#utils"; |
3 | 3 | import { FormattedCodeBuilder, FormattedCodeGenerator, type FormatterNode, Wrap } from "../../../formatter.js"; |
4 | 4 | import { hasTypeParameters } from "../../lib.js"; |
5 | 5 | import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext.js"; |
6 | 6 |
|
| 7 | +function shouldRenderDefaultValue(props: DeclarationReflection) { |
| 8 | + const defaultValue = props.defaultValue; |
| 9 | + |
| 10 | + if (defaultValue === undefined) { |
| 11 | + return false; |
| 12 | + } |
| 13 | + |
| 14 | + /** Fix for #2717. If type is the same as value the default value is omitted */ |
| 15 | + if (props.type && props.type.type === "literal") { |
| 16 | + const reflectionTypeString = props.type.toString(); |
| 17 | + |
| 18 | + if (reflectionTypeString === defaultValue.toString()) { |
| 19 | + return false; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + return true; |
| 24 | +} |
| 25 | + |
7 | 26 | export function memberDeclaration(context: DefaultThemeRenderContext, props: DeclarationReflection) { |
8 | 27 | const builder = new FormattedCodeBuilder(context.router, context.model); |
9 | 28 | const content: FormatterNode[] = []; |
10 | 29 | builder.member(content, props, { topLevelLinks: false }); |
11 | 30 | const generator = new FormattedCodeGenerator(context.options.getValue("typePrintWidth")); |
12 | 31 | generator.node({ type: "nodes", content }, Wrap.Detect); |
13 | 32 |
|
14 | | - /** Fix for #2717. If type is the same as value the default value is omitted */ |
15 | | - function shouldRenderDefaultValue() { |
16 | | - if (props.type && props.type.type === "literal") { |
17 | | - const reflectionTypeString = props.type.toString(); |
18 | | - |
19 | | - const defaultValue = props.defaultValue; |
20 | | - |
21 | | - if (defaultValue === undefined || reflectionTypeString === defaultValue.toString()) { |
22 | | - return false; |
23 | | - } |
24 | | - } |
25 | | - return true; |
26 | | - } |
27 | | - |
28 | 33 | return ( |
29 | 34 | <> |
30 | 35 | <div class="tsd-signature"> |
31 | 36 | {generator.toElement()} |
32 | | - {!!props.defaultValue && shouldRenderDefaultValue() && ( |
33 | | - <> |
34 | | - <span class="tsd-signature-symbol"> |
35 | | - {" = "} |
36 | | - {props.defaultValue} |
37 | | - </span> |
38 | | - </> |
| 37 | + {shouldRenderDefaultValue(props) && ( |
| 38 | + <span class="tsd-signature-symbol"> |
| 39 | + {" = "} |
| 40 | + {props.defaultValue} |
| 41 | + </span> |
39 | 42 | )} |
40 | 43 | </div> |
41 | 44 |
|
|
0 commit comments