Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
Does TypeScript support export default Enum?

I have an enum object which I want to make the export default at the top level like that :

export default enum Hashes{

FOO = 'foo',
BAR = 'bar',
}

I got this error :

Module parse failed: Unexpected token (1:15) File was processed with these loaders: [02:54] MABROUK, Sahnoun (external - Project)

  • ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
  • ./node_modules/@ngtools/webpack/src/ivy/index.js

I tried this way :

export enum Hashes{
    
    FOO = 'foo',
    BAR = 'bar',
    }

and it seems work only if I import Hashes as alias in all my components like that :

import {Hashes} from ... which is a huge change in my project !

any solution ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This is how ES6 works.

enum Hashes {
    
    FOO = 'foo',
    BAR = 'bar',
    }

export default Hashes;

Exporting it as const? Concerning the default export, there is only a single default export per module. A default export can be a function, a class, an object or anything else. This value is to be considered as the "main" exported value since it will be the simplest to import.

export const enum Hashes {

FOO = 'foo',
BAR = 'bar',
}
about 4 years ago · Juan Pablo Isaza Report

0

export default expects an expression/function/class after it, you can read here more Export MDN

This is not due to TS, this is due to error in your statement. You can simply defined you enum first and then export it default.

enum Hashes {
 FOO = 'foo',
 BAR = 'bar',
}

export default Hashes
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!