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

131
Visualizações
Typescript export const foo vs export default { foo }

Are the three export options exactly equivalent?

// foo.ts
export const foo = () => {}
// foo.ts
const foo = () => {}
export default { foo }
// foo.ts
const foo = () => {}
export { foo }

Disclaimer: I know that import { foo } from './foo' will work just the same in all scenarios but are there any nuances?

Particularly interested in any nuances that might occur when having a mixed ts and js codebase.

Using tsconfig "module": "CommonJS", nodejs v14 and typescript 4.2.4

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The short answer is no they're not the same, they have different syntax, but let's be serious.

export const foo = () => {}

...

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = void 0;
var foo = function () { };
exports.foo = foo;

Is what that compiles to using commonjs and es5 as target.

const foo = () => {}
export default { foo }

...

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var foo = function () { };
exports.default = { foo: foo };

Is what that compiles to.

const foo = () => {}
export { foo }

...

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = void 0;
var foo = function () { };
exports.foo = foo;

Is what that compiles to.

Along with that it should also be noted that using:

export { foo }

Can only be imported using:

import {foo} from './foo'

While using:

export default { foo }

Can only be imported using:

import whatever from './foo'

// use whatever.foo
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