4

I'm using typescript, and trying to use an ES6 map, but getting compile errors.

I've discerned that I need to reference the file lib.core.es6.d.ts (ES6 Map in Typescript), and I know where that is on my filesystem. However, I can't find anything that specifies what to do to use that file.

Right now, I just have two files in a folder which I'm compiling with tsc --module amd treenode.ts treemerge.ts

How do I use the es6 types in one of those files? If the answer is "restructure your project the way site X says to", I'll grumble but I guess that's ok.

2 Answers 2

4

However, I can't find anything that specifies what to do to use that file.

You need to get that file manually from github AND compile your project with --noLib passing in the lib file yourself.

Sign up to request clarification or add additional context in comments.

1 Comment

Like this? { "compileOnSave": true, "compilerOptions": { "target": "es5", "noLib": true }, "files": [ "app/*.ts", "scripts/lib.es6.d.ts" ] }
4

The default build target is targeting ES5 which then forces the compiler to use the default lib.core.d.ts, because it cannot assume that the ES6 types will be available.

If you set your target to ES6 the compiler will automatically target the lib.core.es6.d.ts, without you having to do that yourself. This does have the disadvantage that your compiled output will also be ES6 compliant JavaScript instead of ES5. What that means for example, is that if you use any classes in your TypeScript code, the compiler will output JavaScript classes to the output file.

To get around this, you can either manually change the reference to lib.core.es6.d.ts as basarat mentions, or you can add in something like babel that will transpile the ES6 code to compliant ES5 code for you automatically.

As an example I've recently moved over omnisharp-atom and omnisharp-client to target ES6 and use babel as an additional transpiler to produce ES5 source files.

https://github.com/OmniSharp/omnisharp-node-client/blob/master/tsconfig.json#L7-L9 https://github.com/OmniSharp/omnisharp-atom/blob/master/gulpfile.js#L45-L52 https://github.com/OmniSharp/omnisharp-node-client/blob/master/gulpfile.js#L54-L61

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.