devmiles.com devmiles.com - 2 months ago 9
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
undefined
is a valid type in TypeScript.

Advanced Types mentions union types like
number | undefined
.

What's wrong with my union type declaration?

Answer

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

Comments