Skip to content

QuizNot attempted

Which narrowings work?

Given x: string | number | Date | { kind: 'a' } | null, which checks narrow the type?

Select all that apply.

1–4 to choose, Enter to submit
Show answer & explanation

Correct answers:

  • typeof x === 'string'
  • x instanceof Date
  • typeof x === 'object' && x !== null && 'kind' in x
  • typeof x === 'string', x instanceof Date, and the typeof ... 'object' + !== null + 'kind' in x chain are all control-flow narrowings TS understands.
  • Not x as Date: an assertion overrides the type for that expression with no runtime check, it never narrows x itself.