react-tailwindcss-select icon indicating copy to clipboard operation
react-tailwindcss-select copied to clipboard

Improve types

Open t1nky opened this issue 1 year ago • 0 comments

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>;

t1nky avatar Mar 21 '23 17:03 t1nky