james
james

Reputation: 389

Typescript: Multiple possible interfaces as an interface

If I have a variable like this:

let x: number | string | undefined;

Is it possible to create an interface that supports all these types? Something like:

let x: MyCustomInterface;

Thanks!

Upvotes: 1

Views: 167

Answers (1)

Madara's Ghost
Madara's Ghost

Reputation: 175078

No, interfaces do not support unions inside of themselves. You can make a type alias though:

type MyCustomType = number | string | undefined;
let x: MyCustomType;

Upvotes: 2

Related Questions