Published on

Ts imposer un type ou un autre

Author

En spécifiant un type ou un autre, nous imposons que telle ou telle propriété devrait être obligatoire dans un type mais pas dans l'autre.

export type FormConfirmationProps<V extends FormValues> = {
  requireConfirmation: true
  onConfirm: OnConfirmForm<V>
  onSubmit?: never
}

export type FormNoConfirmationProps<V extends FormValues> = {
  requireConfirmation?: never
  onConfirm?: never
  onSubmit: OnSubmitForm<V>
}

export type FormProviderProps<V extends FormValues> = {
  ...
} & (FormConfirmationProps<V> | FormNoConfirmationProps<V>)