I am attempting to break down an object and remove a specific property from it.
Here is the current approach I am taking:
let x = {a:1, b:2, c:3};
let y = {...x};
delete y.c;
store.setState(y);
I came across an article discussing ES7 that introduced a new method for excluding properties. The revised code would look like this:
let x = {a:1, b:2, c:3};
store.setState({c, ...x});
https://codeburst.io/use-es2015-object-rest-operator-to-omit-properties-38a3ecffe90
Unfortunately, the above technique does not function properly in Angular 7, resulting in the following error message:
error TS2663: Cannot find name 'c'. Did you mean the instance member 'this.c'?
I am currently using TypeScript 3.1.6, and my tsconfig.app.json file appears as follows.
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": []
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
Below is the parent file.
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"importHelpers": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
It seems that specifying "lib": ["es2017"]
pertains to ES6, which may be causing the issue.
How can I enable this ES7 feature without affecting the target ES5 output from TypeScript?