- 24 days ago 4
TypeScript Question

Cannot find name 'undefined' in union type

I'm declaring a variable:

Id: string | string[] | undefined;

This results in error

TS2304: Cannot find name 'undefined'.

According to Basic Types
is a valid type in TypeScript.

Advanced Types mentions union types like
number | undefined

What's wrong with my union type declaration?


The undefined type, together with the null type, was only introduced in TypeScript 2.0. You're probably using an older version of TypeScript.