How to import an enum with TypeScript?

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.