javascript - typescript 对象解构结果为 "Property assignment expected."

标签 javascript typescript ecmascript-2016 destructuring

我正在将一个项目从 Babel 转换到 Typescript 并收到以下编译器错误:

error TS1136: Property assignment expected.

来自如下代码:

var auth = {...this.props.auth};

此代码以前在 Babel 下运行良好,但在尝试通过 Typescript 编译时导致上述错误。 Typescript 中的对象解构是否不同?

最佳答案

您要找的特征是Object spread/rest operators (建议用于 ES7)。看起来已经计划但尚未实现:

We want to wait for the proposal to reach Stage 3 before addressing this.

更多信息 here .

编辑:提案处于第 3 阶段。我们很可能会看到它是在 ES2018 (ES9) 上起草的。 Support has been added to TypeScript as well (从 2.1 开始)。

关于javascript - typescript 对象解构结果为 "Property assignment expected.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34880496/

相关文章:

typescript - Firebase Functions Typescript - 使用 html 模板发送电子邮件

ElementRef 上的 Angular2 getElementsByClassName

javascript - Typescript 在语法方面与 es6/es7 有多少不同

javascript - 有没有办法在底层范围内重用 if(...) 条件的值?

javascript - Mongoose 未保存正确的架构

javascript - 类型错误 : Cannot read property 'http' of undefined

javascript - 如何在不同页面上发表不同意见

javascript - ECMAScript 6 或 7 是否支持静态类型?

javascript - javascript中的文件下载进度

javascript - 如何检查 map 功能是否完成