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

78
Visualizações
Export method from imported module

Consider the following example where I import a module with an indefinite number of items:

import * as module from './module.js';

const something = () => {
  // Also doing something with other methods from the imported module.
  return module.method1() * 2;
}


export {
  something as default,
  module.method2 as method2 // THIS DOES NOT WORK!!
}

I want to export method2 from the imported module, but I can't make it work.

Also I don't benefit from destructuring because I also use an indefinite number of methods in the code (not pictured in the example).

How can I achieve this?
Can I export it directly without assigning the method2 to a new variable before exporting?

Also worth nothing that I might use the same method name or not.
Does this influence the outcome, apart from using x as y?

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

0

You're probably looking for a separate

export { method2 } from './module.js';
// or
export { method2 as methodAlias } from './module.js';
// or with a local identifier:
import { method2 } from './module.js';
export { method2 }

If you only want to refer to the module namespace object, and not repeat the imported module specifier, then yes you need to create an extra variable to export it.

export const method2 = module.method2;
// or
export const { method2 } = module;
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