javascript - 在提供的参数上解构对象
问题描述
我想不出一种从提供的参数中解构对象的方法:
type PossibleStateProperty = 'hello' | 'world'
type State = {
hello: 'welcome',
world: 'earth'
}
handleError = (name: PossibleStateProperty) => {
const { [name] } = this.state
}
我将state
根据提供的函数参数解构对象属性。
const { [name] } = this.state
可悲的是无效
解决方案
推荐阅读
- julia - 无法在 Julia 1.0 中安装“DateTime”包?
- list - 使用 Jinja for-loop 遍历字典列表
- javascript - 在承诺解决之前表达 JS 退出 API
- algorithm - 神经网络和遗传算法
- oracle - Docker - 运行 Oracle DB 映像并执行初始化脚本
- apache-spark-sql - 在 spark sql (java) 中加入两个数据集
- python - MapReduce 作业因 ExitCodeException exitCode=1 而失败
- primefaces - p:column sortBy value 表达式不计算列索引
- c# - .net C# jdbc 驱动程序连接器异常
- android - 如何以编程方式更改每次旋转的进度对话框环颜色?(支持应该是最新的API)