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

267
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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