I know this is 100% a noob question, but i can't handle myself and want to know an answer.
type SweetAlertPosition =
'top' | 'top-start' | 'top-end' | 'top-left' | 'top-right' |
'center' | 'center-start' | 'center-end' | 'center-left' | 'center-right' |
'bottom' | 'bottom-start' | 'bottom-end' | 'bottom-left' | 'bottom-right';
Main interface(simplified):
interface SweetAlertOptions {
...,
position?: SweetAlertPosition
}
class Swal {
mixin(options: SweetAlertOptions)
}
Now, if i explicitly pass options to .mixin call: Swal.mixin({ position: 'bottom' }) - no error is there. But if i predefine options in some const object:
defaultOptions = {
position: 'bottom'
}
Passing now make an error - Swal.mixin(defauiltOptions)
Types of property 'position' are incompatible.
Type 'string' is not assignable to type '"top" | "top-start" | "top-end" | "top-left" | "top-right" | "center" | "center-start" | "center-end" | "center-left" | "center-right" | "bottom" | "bottom-start" | "bottom-end" | "bottom-left" | "bottom-right" | undefined'.
I already found out that a have to cast String type to const:
defaultOptions = {
position: 'botton' as const | as SweetAlertPosition
}
But why passing options via const obj(defaultOptions) make position property become String-type, and passing it directly does not oO ?