Use of template literals and Exclude keyword
- Using tempalte literals to create many strings by making use of unions.
import { Toast } from './components/templateliterals/Toast'
function App() {
return (
<div className='App'>
<Toast position='center' />
</div>
)
}
type HorizontalPosition = 'left' | 'center' | 'right'
type VerticalPosition = 'top' | 'center' | 'bottom'
type ToastProps = {
position:
| Exclude<`${HorizontalPosition}-${VerticalPosition}`, 'center-center'>
| 'center'
}
export const Toast = ({ position }: ToastProps) => {
return <div>Toast Notification Position - {position}</div>
}