- 1 year ago 184
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download