I've noticed some web projects using typescript and webpack also use babel to finish off the compilation. For example, they use ts to compile to ES2015 and then use babel to compile to es5. Why not just use ts directly to compile to es5?
Is it in the case the project also has js that needs to be compiled so they just use babel for everything? Or what am I missing?
Thanks.
There's a few possible reasons for this.
Promise
, Symbol
, etc). This allows you to decide which implementation of these polyfills will work the best for you, but it can be a pain. Babel spares you the burden of thinking about that. It's a tradeoff.async
/await
in ES5) - TypeScript has supported async
/await
in ES5 since 2.1, and has supported generators behind the downlevelIteration
flag since 2.3. Before that, users often relied on Babel to pick up the slack, but Babel isn't needed here anymore.allowSyntheticDefaultImport
option which tells TypeScript that default imports can be used to import certain modules. Babel supports this behavior, but Webpack didn't until Webpack 2 came out. Babel isn't needed here anymore for newer versions of Webpack.This might not be the complete set of reasons, but it's a few I can think of off the top of my head.