#Allow only one of multiple interfaces?
8 messages · Page 1 of 1 (latest)
hmm, I tried that but it doesn't seem to do what I want. ts doesn't complain if I have both icon/text defined
I have export const Button = ({ onClick, ...props }: IconButtonProps | TextButtonProps): JSX.Element => { but all of my uses of that component totally allow both icon/text attrs
type PickOne<T> = { [K in keyof T]: Pick<T, K> }[keyof T]
type Props = PickOne<{ text: string, icon: JSX.Element }> & TypedButtonProps
idk something like this i guess then
hm, still doesn't have any affect. I'll have to dig deeper
type ExactlyOne<T> = { [K in keyof T]: { [P in keyof T]: P extends K ? never : T[P] } }[keyof T]
this seems to work https://dev.to/maissenayed/conditional-react-props-with-typescript-43lg - using never