Sri
Sri

Reputation: 97

How to use later version of es that is later to es2015 in Visual Studio Code

Haii I am New to visual Studio , i have created a simple Type Script file Test.ts Here is the code

let hm:Map<number,String> = new Map<number,String>();
let uname=1;
let pass="String";
hm.set(uname,pass);
console.log(hm);

i am compiled the file using tsc Test.ts

but i am getting following error could some one help me how to resolve , i am not using angular just a type script file thats it

Test.ts:1:8 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2015' or later.

1 let hm:Map<number,String> = new Map<number,String>();

how to resolve this error , do i need to use tsconfig.json necessarily or i can change the Editor to use later version of es2015 directly

Upvotes: 3

Views: 6391

Answers (2)

Evgeny Mikhaylov
Evgeny Mikhaylov

Reputation: 56

If you invoke tsc with a filename it ignores tsconfig.json. It should work if you just execute tsc without any CLI arguments.

So I

  1. created the tsconfig.json file by calling tsc --init;
  2. uncommented the "lib": [] property;
  3. added "es2015" to the lib array: "lib": ["es2015"];
  4. typed tsc in the command line;
  5. killed bugs;
  6. repeated action 4

and that helped: I got the file.js script that could be executed by node file.js!

Upvotes: 0

Mohan Raj Raja
Mohan Raj Raja

Reputation: 156

In the tsconfig.json, try adding the target library as below

{
  "compilerOptions": {
    "target": "es5"
  }
}

Upvotes: 1

Related Questions