Skip to content

Commit

Permalink
simplified checking if type should be rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
Corso02 committed Sep 30, 2024
1 parent eb87d44 commit b9f56e0
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions src/lib/output/themes/default/partials/member.declaration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,16 @@ export function memberDeclaration(context: DefaultThemeRenderContext, props: Dec

const visitor = { reflection: renderTypeDeclaration };

/** Fix for #2717. If type is the same as value the type is omited */
/** Fix for #2717. If type is the same as value the type is omitted */
function shouldRenderType() {
if (props.type && props.type.type === "literal") {
const typeObject = props.type.toObject();
const value = typeObject.value;
if (!value) {
// should be unreachable
return true;
}
if (typeof value === "object") {
return true;
}
const reflectionTypeString: string = value.toString();
let defaultValue = props.defaultValue!;
if (defaultValue) {
// If the default value is string and it's wrapped in ' in the code, the value is wrapped in " and vice-versa
if (
(defaultValue[0] === '"' && defaultValue[defaultValue.length - 1] === '"') ||
(defaultValue[0] === "'" && defaultValue[defaultValue.length - 1] === "'")
) {
defaultValue = defaultValue.slice(1, -1);
}
}
const reflectionTypeString = props.type.toString();

const defaultValue = props.defaultValue;

if (reflectionTypeString === defaultValue.toString()) {
if (defaultValue === undefined || reflectionTypeString === defaultValue.toString()) {
return false;
}
return true;
}
return true;
}
Expand Down

0 comments on commit b9f56e0

Please sign in to comment.