You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Transpilation of ES6 imports is inconsistent with babel #5458
but I get an error when running it with babel's transpilation:
TypeError: object is not a function
at Object.<anonymous> (./test.js:7:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
To get it to work with babel, I have to do the following:
importrpfrom'request-promise';
but that returns an error when compiling with typescript:
test.ts(1,8): error TS1192: Module ''request-promise'' has no default export.
I currently have a pipeline of typescript --tsc--> es6 --babel--> es5 so that I can use async/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 that tsc 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
33,936 downloads in the last day
174,998 downloads in the last week
551,455 downloads in the last month
npm typescript
15,303 downloads in the last day
101,148 downloads in the last week
357,086 downloads in the last month
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.
Jacob Eggers (@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 export default.
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 rp though this way:
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 request-promise because the function can take an Options parameter that has all optional properties, meaning the following is valid typescript:
Mohamed Hegazy (@mhegazy) The declaration is accurate for how typescript handles the transpilation, but the issue is that babel handles transpilation differently, and when I go ts-->es6-->es5 for babel's async/await support, i have to make declaration changes.
Activity
jkillian commentedon Oct 30, 2015
Jacob Eggers (@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
export default.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
rpthough this way:eggers commentedon Oct 30, 2015
Jason Killian (@jkillian)
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
request-promisebecause the function can take anOptionsparameter that has all optional properties, meaning the following is valid typescript:I put more details here: DefinitelyTyped/DefinitelyTyped#6489
mhegazy commentedon Oct 30, 2015
this looks like a typing issue. if
request-promisehas a default export it should be in the .d.ts file.jkillian commentedon Oct 30, 2015
There's already an
export =in the typings, but that has to be changed toexport defaultto work correctly with TS and Babel at the momenteggers commentedon Oct 30, 2015
Mohamed Hegazy (@mhegazy) The declaration is accurate for how typescript handles the transpilation, but the issue is that babel handles transpilation differently, and when I go
ts-->es6-->es5for babel's async/await support, i have to make declaration changes.mhegazy commentedon Nov 13, 2015
Looks like this will be handled by #5577
mhegazy commentedon Nov 13, 2015
see #5285 for more details.