简体   繁体   English

是否可以一起使用TypeScript和Babel

[英]is it possible to use TypeScript and Babel together

I am new to both TypeScript and Babel. 我是TypeScript和Babel的新手。 I have researched both and found they have features the other does not have. 我研究了两者,发现它们具有其他没有的功能。 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. 我希望通过使用TypeScript来组织我的代码,然后使用像asyc / await和其他人一样的babel ES6功能来充分利用这两个世界。 Is this possible. 这可能吗。

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. 我希望通过使用TypeScript来组织我的代码,然后使用像asyc / await和其他人一样的babel ES6功能来充分利用这两个世界。 Is this possible. 这可能吗。

Not out of the box. 没有开箱即用。 I would recommend against it unless you are willing to start compiler hacking yourself. 我建议反对它,除非你愿意自己开始编译器黑客攻击。 Reason is that since TypeScript doesn't understand async await yet you need to put babel before TypeScript and then the output generated by Babel will not be ideal TypeScript compilation target. 原因是,由于TypeScript不理解async等待你需要 TypeScript 之前放置babel,然后Babel生成的输出将不是理想的TypeScript编译目标。

That said TypeScript should get async/await soon (3 / 4 months) 那说TypeScript应该很快就会异步/等待(3/4个月)

Update 更新

You can now use TypeScript async/await with --target es6 and then use babel as a secondary transpiler. 您现在可以使用TypeScript async/await--target es6 ,然后使用babel作为辅助转换器。

In fact atom-typescript supports typescript -> babel -> js out of the box : https://github.com/TypeStrong/atom-typescript/blob/master/docs/faq.md#can-i-use-an-alternate-transpiler 事实上,atom-typescript支持开箱即用的typescript -> babel -> jshttps//github.com/TypeStrong/atom-typescript/blob/master/docs/faq.md#can-i-use-an-交替transpiler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM