// Project: Immutability helper // TypeScript Version: 2.9 export default update; declare function update = never>( target: T, spec: Spec, ): T; declare namespace update { function newContext(): typeof update; function extend( command: string, handler: (param: any, old: T) => T, ): void; } // Usage with custom commands is as follows: // // interface MyCommands { // $foo: string; // } // // update>(..., { $foo: "bar" }); // // It is suggested that if you use custom commands frequently, you wrap and re-export a // properly-typed version of `update`: // // function myUpdate(object: T, spec: Spec>) { // return update(object, spec); // } // // See https://github.com/kolodny/immutability-helper/pull/108 for explanation of why this // type exists. export type CustomCommands = T & { __noInferenceCustomCommandsBrand: any }; export type Spec = never> = | ( T extends (Array | ReadonlyArray) ? ArraySpec : T extends (Map | ReadonlyMap) ? MapSpec : T extends (Set | ReadonlySet) ? SetSpec : T extends object ? ObjectSpec : never ) | { $set: T } | { $apply: (v: T) => T } | ((v: T) => T) | (C extends CustomCommands ? O : never); type ArraySpec> = | { $push: T[] } | { $unshift: T[] } | { $splice: Array<[number] | [number, number] | [number, number, T]> } | { [index: string]: Spec }; // Note that this does not type check properly if index: number. type MapSpec = | { $add: Array<[K, V]> } | { $remove: K[] }; type SetSpec = | { $add: T[] } | { $remove: T[] }; type ObjectSpec> = | { $toggle: Array } | { $unset: Array } | { $merge: Partial } | { [K in keyof T]?: Spec };