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

77
Views
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 answers
Answer question

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 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!