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?
-
Wouldn't you be able to use the standard ES6 definitions from typescript? github.com/Microsoft/TypeScript/blob/master/bin/lib.es6.d.ts Or do you mean how would you load the library?loganfsmyth– loganfsmyth2015-07-14 21:43:15 +00:00Commented Jul 14, 2015 at 21:43
-
Ah, yes I can use that! Thanks!Mark Volkmann– Mark Volkmann2015-07-15 18:45:16 +00:00Commented Jul 15, 2015 at 18:45
2 Answers
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.
Comments
The Typescript repo provides standard definitions for ES6 functionality.
I suppose if you wanted to use some of core-js's functionality that is beyond ES6, you would have to add definition files yourself.