我正在学习使用typescript的angular2.它非常吸引人,但是我很难理解任何应用程序的实际工作,因为我们编写的代码将在typescript中.但是要执行的代码总是在ECMAScript中.
我听说过有关转换器的信息,但却无法理解它.
我只是想知道这个功能是如何实现的?
解决方法
有两种方法可以做到这一点:
>即时传输(就像在plunkr中完成的那样):
<script> System.config({ transpiler: 'typescript',typescriptOptions: { emitDecoratorMetadata: true },packages: { 'app': { defaultExtension: 'ts' } } }); (...) </script>
这是一个示例:https://plnkr.co/edit/aG4TdHbAls3cu04AAt64
>使用typeScript编译器预处理TypeScript文件.然后你只依赖编译的JavaScript文件.在angular.io:https://angular.io/guide/quickstart的5min快速入门中描述了这种方法.