Fix error with empty union

This commit is contained in:
Misode
2024-10-28 06:18:32 +01:00
parent bdc06d1f43
commit a536c78e05

View File

@@ -286,6 +286,10 @@ function BooleanHead({ node, makeEdit }: Props) {
function UnionHead({ type, optional, node, makeEdit, ctx }: Props<UnionType<SimplifiedMcdocTypeNoUnion>>) {
const { locale } = useLocale()
if (type.members.length === 0) {
return <></>
}
const selectedType = findSelectedMember(type, node)
const onSelect = useCallback((newValue: string) => {
@@ -931,6 +935,9 @@ function getDefault(type: SimplifiedMcdocType, range: core.Range, ctx: McdocCont
}
}
if (type.kind === 'union') {
if (type.members.length === 0) {
return { type: 'json:null', range }
}
return getDefault(type.members[0], range, ctx)
}
if (type.kind === 'enum') {