Skip to content

CodeNot attempted

Type challenge: toast positions

Difficulty: easy

Use template literal types to build ToastPosition (every horizontal-vertical pair except 'center-center', plus 'center') and CssLength (a number followed by px, rem or %). Check types is the test.

Show reference solution
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' | '%'}`;
Loading editor…