角钢2的移栽过程

4 angular

因为我是角2和学习的新手。

我使用链接https://www.tutorialspoint.com/typescript/typescript_environment_setup.htm引用了angular 2教程

在这里,我知道打字稿正在被编译为javascript。

并且在对angular 2应用进行编码时,我在tsconfig.json文件中发现如下所示:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

在这里,“ target”:“ es5”规范表明该打字稿已转换为es5标准,即ECMAScript2009和“ lib”:[“ es2017”,“ dom”]规范表明其使用了es2017库。

任何人都可以澄清角2的移植概念吗?

我们可以将“ target”:“ es5”更改为es6即ECMAScript2015吗?

以及“ lib”:[“ es2017”,“ dom”]到底指定了什么?

Pra*_*ana 6

任何人都可以澄清角2的移植概念吗?

编译代码与编译过程类似,但有很大的不同。

  • 编译:将高级语言的代码转换为机器级语言。

  • 转译:将高级语言的代码转换为另一种高级语言。

因此,在Angualr Transpile中,您将用Typscript编写的内容转换为另一种高级语言,即Javascript。这是因为所有现代浏览器只能理解Javascript。

我们可以将“ target”:“ es5”更改为es6即ECMAScript2015吗?

以及“ lib”:[“ es2017”,“ dom”]到底指定了什么?

为此,您可以阅读https://angular.io/guide/typescript-configuration,是的,您可以将es5更改为es6

只需更新:ES5是当前的稳定版本,因此如果您设置目标ES5,则编译器将根据ES5版本生成javascript文件。如果将其更改为ES6,它将根据Es6标准生成javascript文件;但是,并非所有浏览器都完全支持ES6。

为了能够使用TS源中ES标准库中的类,应使用lib选项并指定源中使用的所有标准ES6库接口。例如,要使用ES6和DOM中的Reflect对象或Array.from,请配置以下内容:

{
  "compilerOptions": {
    "lib": ["es6", "dom"],
  }
}
Run Code Online (Sandbox Code Playgroud)

在此处阅读更多信息:https : //blog.angularindepth.com/configuring-typescript-compiler-a84ed8f87e3