2017-07-03 34 views
0

我从@types/immutability-helper导入update。现在我想将一个项目推送到一个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; 
} 

意思我有写2个更新?:

this.setState(update(this.state, update(this.state.Markers, { $push: [info] }))); 

还是什么?

回答

0

这是为我工作的语法:

this.setState(update(this.state, { Markers: { $push: [info] } })); 

这是不是从打字稿定义文件明显。但the docs说这样的事情。