2017-07-03 53 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說這樣的事情。