我是 TypeScript 和 Babel 的新手。我对两者都进行了研究,发现它们具有另一个所没有的功能。我想通过使用 TypeScript 来组织我的代码,然后使用 babels ES6 功能(如 asyc/await 等)来两全其美。这可能吗。
最佳答案
I'd like get the best of both world by using TypeScript to organize my code then use babels ES6 features like asyc/await and others. Is this possible.
不是开箱即用的。我建议不要这样做,除非你愿意自己开始编译器黑客攻击。原因是由于 TypeScript 不理解异步等待,但您需要将 babel 放在 TypeScript 之前,然后 Babel 生成的输出将不是理想的 TypeScript 编译目标。
也就是说 TypeScript 应该很快就会有 async/await(3/4 个月)
更新
您现在可以将 TypeScript async/await
与 --target es6
一起使用,然后使用 babel 作为辅助转译器。
事实上 atom-typescript 支持 typescript -> babel -> js
开箱即用:https://github.com/TypeStrong/atom-typescript/blob/master/docs/faq.md#can-i-use-an-alternate-transpiler
关于javascript - 是否可以一起使用 TypeScript 和 Babel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30801857/