0

I thought that Typescript supported all the new constructs of ES6. I was just playing with examples from http://www.2ality.com/2015/08/es6-map-json.html and for example,

var a = new Map([[true, 7], [{foo: 3}, ['abc']]])

Gives errors, lots of them. Where am I going wrong?

5
  • 1
    Yes, Typescript is different from ES6, although it has incorporated many of the ES6 constructs. Commented Aug 18, 2015 at 15:21
  • 1
    Can you post the errors, please? Commented Aug 18, 2015 at 15:21
  • Also, make sure the compiler is targeting ES6. TypeScript doesn't do this by default. You can do this by setting the --target flag. Commented Aug 18, 2015 at 17:46
  • @mallison dont use --target es6 unless the runtime supports all the es6 features that typescript at the moment ..... which at the time of this writing are none of node/chrome/firefox. So Don't Commented Aug 19, 2015 at 0:58
  • @basarat The question is about writing ES6, where it can be used or not is irrelevant. It could be sent through something Babel. Commented Aug 19, 2015 at 14:41

2 Answers 2

2

Most likely you'll need to write a .d.ts typing for it.

Here's one that is as simple as it gets to allow you to instantiate the class the way you would expect.

interface MapStatic {
    new(m: any): MapInstance;  /*Use 'any' if you don't want typing, 
                               and don't want to maintain the MapInstance */
}
interface MapInstance {
}
declare var Map: MapStatic;

Just in case you need it, here's the guide.

The Typescript roadmap says that Map is a complete feature. I'd double check to make sure you have the latest typescript installation. Get it through node.js with this install command:

npm install -g typescript

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

1 Comment

Yes I did have the latest typescript, but didn't import the typing file for it. That's likely my problem.
0

but I thought that Typescript supported all the new constructs of ES6

Not all of them. See : https://kangax.github.io/compat-table/es6/ Specifically

1 Comment

That does answer the title of this question. But, as far as Map itself is concerned, which was my example, that is fully supported per the compat table.

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.