Back

Type Guards / typeof Type Guard

00:00
1/20

typeof Type Guard

Easy

'Write a function process(val: string | number) that returns val.length if it is a string, and val.toFixed(2) if it is a number.'

  • 1

    Use typeof val === 'string' and typeof val === 'number'.

TYPESCRIPT PLAYGROUND
TYPESCRIPT PLAYGROUND
⏳ Loading editor…