Angular2 why do we need the es6-shim

后端 未结 2 1028
灰色年华
灰色年华 2021-02-07 03:27

Following the Angular2 Quickstart Guide we are instructed to include es6-shim in 2 places:

1) index.html

2条回答
  •  野性不改
    2021-02-07 03:45

    TypeScript does not come with built-in polyfills. There are certain features it doesn't transpile, this is where polyfills like es-shim come in.

    The TypeScript definition file will provide you with typing support within your chosen editor and the es-shim will provide the implementation for the functionality that TypeScript doesn't transpile to ES5 code.

    A few of such features TypeScript doesn't transpile are:

    • Promises
    • Functions hanging off of prototype objects (Array.from(),Array.of(),Number.isInteger(), etc)
    • Module loading

    The general approach is:

    The rule of thumb is that if there's a canonical/sane emit that doesn't have a huge perf-hit, we'll try to support it. We don't add any runtime methods or data structures, which is more what core.js (or any pollyfil) serves to do. - source (TypeScript developer)

提交回复
热议问题