Ir para o conteúdo

CódigoNão tentada

Desafio de tipos: posições de toast

Dificuldade: fácil

Use template literal types para construir ToastPosition (todo par horizontal-vertical exceto 'center-center', mais 'center') e CssLength (um número seguido de px, rem ou %). Check types é o teste.

Ver solução de referência
export type Horizontal = 'left' | 'right' | 'center';
export type Vertical = 'top' | 'bottom' | 'center';
// A template literal over unions expands to their cross product; Exclude drops the redundant one.
export type ToastPosition = Exclude<`${Horizontal}-${Vertical}`, 'center-center'> | 'center';
// `${number}` matches any numeric string, so this checks the shape, not just "some string".
export type CssLength = `${number}${'px' | 'rem' | '%'}`;
Carregando editor…