Created
September 7, 2018 18:45
-
-
Save superamadeus/ddafcc9b18a1c2ac9e0d2d515f698a15 to your computer and use it in GitHub Desktop.
Namespaced imports proposal for TC39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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