timolins / react-hot-toast

Smoking Hot React Notifications 🔥
https://react-hot-toast.com
MIT License
9.66k stars 319 forks source link

Feature request: convert Type and Position to enum #212

Closed mkbctrl closed 2 years ago

mkbctrl commented 2 years ago

Hey, I wanted to ask what do you think about converting the:

declare type ToastType = 'success' | 'error' | 'loading' | 'blank' | 'custom';
declare type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';

into enums?

That way we can use the enum in a code like:

import { ToastPosition } from 'react-hot-toast';

/**
 * @description default configuration for all toast notifications
 **/
export const defaultToastOptions = {
  position: ToastPosition.BottomLeft,
  reverseOrder: false,
  gutter: 10,
  containerStyle: { bottom: 100, left: 20 },
  toastOptions: { duration: 2000 },
}

which seems more type safe. I am happy to create PR, if you like this idea.

timolins commented 2 years ago

Hi! In this case I prefer the string constants for a few reasons:

Why do feel like this would be more type safe?