23622

Question:
For the below code:
const MY_KEY: symbol = Symbol();
let obj: object = {};
obj[MY_KEY] = 123;
console.log(obj[MY_KEY]); // 123
For the below configuration tscconfig.json
:
{
"compilerOptions": {
"lib": ["es2015"]
},
}
<hr />Files
$ ls
tsconfig.json tstut.html tstut.js tstut.ts
<hr />How to resolve below error?
$ tsc --version
Version 2.8.3
$ tsc tstut.ts
tstut.ts(1,24): error TS2304: Cannot find name 'Symbol'.
<hr />Answer1:In your configuration file (tsconfig.json), specify ECMAScript target version to 'ES2015' or later ('ES2016', 'ES2017','ES2018' or 'ESNEXT'). 'ES6' works for me, too.
{
"compilerOptions": {
"target": "ES2015",
}
}