onesine / react-tailwindcss-select

Tailwind Select Component for React.js
https://demo-react-tailwindcss-select.vercel.app/
MIT License
183 stars 38 forks source link

Improve types #37

Open t1nky opened 1 year ago

t1nky commented 1 year ago

Do you think it is possible to use conditional types?

interface Option {
  value: string;
  label: string;
  disabled?: boolean;
  isSelected?: boolean;
}

type SelectValueType<multiple> = multiple extends true
  ? null | Option[]
  : null | Option;
type SelectValueUnion = SelectValueType<true> | SelectValueType<false>;
interface SelectPropsType<T extends boolean> {
  multiple: T;
  value: SelectValueType<T>;
  onChange: (value: SelectValueType<T>) => void;
}
type SelectProps = SelectPropsType<true> | SelectPropsType<false>;