diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index 075b19e4..d7d19c45 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -82,7 +82,7 @@ function Head({ type, optional, node, makeEdit, ctx }: Props) { return } if (type.kind === 'literal') { - return + return } if (type.kind === 'any' || type.kind === 'unsafe') { return @@ -430,8 +430,8 @@ function TupleHead({ type, optional, node, makeEdit, ctx }: Props) { } } -function LiteralHead({ type }: Props) { - return +function LiteralHead({ type, optional, node, makeEdit, ctx }: Props) { + return } function AnyHead({ optional, node, makeEdit, ctx }: Props) { @@ -1210,15 +1210,16 @@ function quickEqualTypes(a: SimplifiedMcdocTypeNoUnion, b: SimplifiedMcdocTypeNo return true } -function findSelectedMember(_union: UnionType, node: JsonNode | undefined) { +function findSelectedMember(union: UnionType, node: JsonNode | undefined) { const selectedType = node?.typeDef if (!selectedType || selectedType.kind === 'any' || selectedType.kind === 'unsafe') { return undefined } if (selectedType.kind === 'union') { + // Find the first selected type that is also part of the original definition. // The node technically matches all members of this union, // ideally the editor should show a combination of all members - return selectedType.members[0] + return selectedType.members.find(m1 => union.members.find(m2 => quickEqualTypes(m1, m2))) } return selectedType }