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

134
Vistas
How to import some functions from a file but not fill up the file namespace with vars that have the same name but also allow for tree shaking

I'm trying to write my imports in a way that is tree shakeable, but I have some functions with the same name as in some other files. Is there a way to import all of these functions into the same file without causing naming conflicts?

Below is a generic example:

// Car.ts
export function doSomething () { /* doSomething logic */ }
export function doSomethingElse () { /* doSomethingElse logic */ }
export function doA3rdThing () { /* doA3rdThing logic */ }

// User.ts
export function doSomething () { /* doSomething logic */ }
export function doSomethingElse () { /* doSomethingElse logic */ }
export function doA3rdThing () { /* doA3rdThing logic */ }

// index.ts
import { doSomething, doSomethingElse, doA3rdThing } from './Car'
import { doSomething, doSomethingElse, doA3rdThing } from './User'

// error: Duplicate identifier 'doSomething'.
// error: Duplicate identifier 'doSomethingElse'.
// error: Duplicate identifier 'doA3rdThing'.

Something like this would be great:

import { doSomething, doSomethingElse, doA3rdThing } as Car from './Car'
import { doSomething, doSomethingElse, doA3rdThing } as User from './User'

Car.doSomething() 
User.doSomething()

// no longer duplicate identifiers and could be tree shakeable
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this:

import { doSomething as carDoSomething, doSomethingElse as carDoSomethingElse } from './Car'
import { doSomething as userDoSomething, doSomethingElse as userDoSomethingElse } from './User'
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