Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

83
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda