Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda