Categories
TypeScript Answers

How to import an enum with TypeScript?

Spread the love

Sometimes, we want to import an enum with TypeScript.

In this article, we’ll look at how to import an enum with TypeScript.

How to import an enum with TypeScript?

To import an enum with TypeScript, we need to export it before we can import it.

To export it, we write

export enum EntityStatus {
  New = 0,
  Active = 1,
  Archived = 2,
  Trashed = 3,
  Deleted = 4,
}

to export the EntityStatus enum with the export keyword.

Then we can import it with

import { EntityStatus } from "../../core/enums";

Conclusion

To import an enum with TypeScript, we need to export it before we can import it.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *