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

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

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