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

270
Views
ES6 import both all (*) and a specific name in the same statement

I have an ES6 module, mod.mjs:

export default { f1, f2 };
export function f1() {}
export function f2() {}

Which I can import and use like this:

import { default as mod, f2 } from "./mod.mjs"
mod.f1();
mod.f2();
f2();

Can I do the same without declaring default export inside mod and without de-structuring * alias after importing it?

I've tried the following but it gives a syntax error:

import { * as mod, f2 } from "./mod.mjs"
mod.f1();
mod.f2();
f2();

Basically I want this, but using the import statement syntax only, if possible:

import * as mod from "./mod.mjs"
const { f2 } = mod;

mod.f1();
mod.f2();
f2();

If there is no pure JavaScript solution to that, perhaps, TypeScript has a syntax for something like that?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

I am not sure if this is what you are expecting. The Best approach you can follow is this:

import * as mod from "./mod.js";
import { f2 } from "./mod";
mod.f1();
mod.f2();
f2();
about 4 years ago · Santiago Gelvez Report

0

You can use code below

import mod, { f1, f2 } from "./fun.mjs";

mod.f1();
mod.f2();
f1();
f2();
about 4 years ago · Santiago Gelvez 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!