Types of property 'icon' are incompatible.
Type 'Element | undefined' is not assignable to type 'Element'.
Type 'undefined' is not assignable to type 'ReactElement<any, any>'.
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
{
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>
}[Keys]
export interface BaseButton {
onClick: () => void
acl?: ToArg<Abilities>
}
type IconType = JSX.Element
export interface RegularButton extends BaseButton {
text: string
icon?: IconType
}
export interface IconButton extends BaseButton {
icon: IconType
}
export type HeaderButton = RequireAtLeastOne<RegularButton & IconButton, 'text' | 'icon'>
const [iconButtons, regularButtons] = !buttons
? [[], []]
: buttons
.filter((button) => !button.acl || aclAbility.can(button.acl))
.reduce(
(acc, button) => {
if (button.icon && !button.text) {
acc[0].push(button)
} else {
acc[1].push(button)
}
return acc
},
[[], []] as [Array<IconButtonType>, Array<RegularButton>],
)