using core-js with TypeScript

Mark Volkmann picture Mark Volkmann · Jul 14, 2015 · Viewed 7.6k times · Source

The Kangax compatibility table for ES6 at http://kangax.github.io/compat-table/es6/ shows results for "TypeScript + core-js". I need core-js in order to use ES6 methods like String#startsWith. I haven't been able to figure out how to tell the TypeScript compiler to consider core-js and couldn't find an example. How can I use core-js with TypeScript?

Answer

user7312303 picture user7312303 · Dec 18, 2016

If you using Typescript 2.0, you can use @types to solve this issue.

@types and types

When you compile typescript code, by default all visible @types packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible; specifically, that means packages within:

  • ./node_modules/@types/,
  • ../node_modules/@types/,
  • ../../node_modules/@types/,

and so on.

@types/core-js provide the definition for core.js, you can install it as another modules.

npm install --save-dev @types/core-js

More information at: tscconfig.json

Good luck.