Skip to content

Instantly share code, notes, and snippets.

@superamadeus
Created September 7, 2018 18:45
Show Gist options
  • Save superamadeus/ddafcc9b18a1c2ac9e0d2d515f698a15 to your computer and use it in GitHub Desktop.
Save superamadeus/ddafcc9b18a1c2ac9e0d2d515f698a15 to your computer and use it in GitHub Desktop.
Namespaced imports proposal for TC39
// Premise: I have names which conflict with names I want to use in another module (rxjs).
// currently possible (annoying to rename everything)
import { race as observableRace, timer as observableTimer, fromEvent as observableFromEvent } from "rxjs";
// currently possible (prevents tree shaking when you only need a few operators.)
import * as RxJsOps from "rxjs";
// currently possible (ugly)
import { race, timer, fromEvent } from "rxjs";
const RxJsOps = { race, timer, fromEvent };
// desired syntax
import { race, timer, fromEvent } as RxjsOps from "rxjs";
/**
* In the first case, the imports are tree-shakeable because you only
* import what you need and you can statically analyze what is used.
*
* In the second case, you lose tree shaking.
*
* The third case is ugly and you have to add your desired names in two places.
*
* I think it would be useful to be able to do the last case.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment