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