-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transpilation of ES6 imports is inconsistent with babel #5458
Comments
@eggers I ran into this same problem today, using the same sort of build pipeline. I ended up with the same solution as you - changing typing files to have an In your first case though, you can also do something like this if you don't want to modify your typings. I'm not sure if you'll be able to have typing support for import * as _rp from 'request-promise';
const rp = (_rp as any).default;
rp('http://github.com').then(console.log); |
Yeah, man that is so ugly. I also don't like the solution because when typescript does finally support async/await --> ES5, and I drop babel from my pipeline, it'd break my code. Also, there are even some other issues with typing support for
I put more details here: DefinitelyTyped/DefinitelyTyped#6489 |
this looks like a typing issue. if |
There's already an |
@mhegazy The declaration is accurate for how typescript handles the transpilation, but the issue is that babel handles transpilation differently, and when I go |
Looks like this will be handled by #5577 |
see #5285 for more details. |
Currently, babel and typescript handle transpilation of ES6 imports differently.
The following works in typescript:
but I get an error when running it with babel's transpilation:
To get it to work with babel, I have to do the following:
but that returns an error when compiling with typescript:
I currently have a pipeline of
typescript --tsc--> es6 --babel--> es5
so that I can useasync/await
while I wait for TypeScript to support it for ES5. However, that means I have to modify all my DefinitelyTyped declarations to have a default export so thattsc
doesn't complain.Discussions of which standard is better for transpilation put aside, my feeling is that TypeScript should follow the standard set by babel rather than using their own since babel is further along at supporting es6, and has a larger community at this point:
npm babel
npm typescript
In addition to keeping in step with the larger community, it would help adoption of typescript by making the transition to typescript from babel more seamless.
The text was updated successfully, but these errors were encountered: