我从update中进口了@types/immutability-helper。现在,我想将一个项推到一个处于React组件状态的数组中。
index.d.ts文件中的语法是:
interface UpdateFunction {
(value: any[], spec: UpdateArraySpec): any[];
(value: {}, spec: UpdateSpec): any;
extend: (commandName: string, handler: CommandHandler) => any;
}而UpdateArraySpec是
interface UpdateArraySpec extends UpdateSpecCommand {
$push?: any[];
$unshift?: any[];
$splice?: any[][];
[customCommand: string]: any;
}这是否意味着我必须写两个更新?:
this.setState(update(this.state, update(this.state.Markers, { $push: [info] })));不然呢?
发布于 2017-07-08 05:15:05
这是对我起作用的语法:
this.setState(update(this.state, { Markers: { $push: [info] } }));这在类型记录定义文件中并不明显。但是医生们说了一些类似的话。
https://stackoverflow.com/questions/44880441
复制相似问题