【发布时间】:2019-05-20 02:02:38
【问题描述】:
我想解构一个对象并排除一个属性。
这就是我现在正在做的事情:
let x = {a:1, b:2, c:3};
let y = {...x};
delete y.c;
store.setState(y);
我发现一篇关于 ES7 的文章指出有一个新功能可以排除属性。所以上面会写成这样:
let x = {a:1, b:2, c:3};
store.setState({c, ...x});
https://codeburst.io/use-es2015-object-rest-operator-to-omit-properties-38a3ecffe90
上述方法在 Angular 7 中不起作用,我收到以下错误:
error TS2663: Cannot find name 'c'. Did you mean the instance member 'this.c'?
我目前正在运行 TypeScript 3.1.6,我的 tsconfig.app.json 文件看起来像这样。
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": []
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
这是父文件。
{
"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"
]
}
}
现在我认为问题在于"lib": ["es2017"] 是针对 ES6 的。
我可以做些什么来启用这个 ES7 功能,它会破坏将 ES5 作为 TypeScript 的编译输出吗?
【问题讨论】:
标签: javascript angular typescript ecmascript-2016