From f50b8998c647fd64e2a21de2a8ffd944f99aee43 Mon Sep 17 00:00:00 2001 From: Tobias Cohen Date: Mon, 14 Nov 2016 06:42:31 +1100 Subject: [PATCH] Fix error in icepick defs for getIn/updateIn, improve generics --- icepick/icepick-tests.ts | 20 ++++++++++++-------- icepick/index.d.ts | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/icepick/icepick-tests.ts b/icepick/icepick-tests.ts index 8c7b654492..5458509d42 100644 --- a/icepick/icepick-tests.ts +++ b/icepick/icepick-tests.ts @@ -27,7 +27,7 @@ class Foo {} // assoc(collection, key, value) { let coll = { a: 1, b: 2 }; - let newColl = i.assoc(coll, "b", 3); // {a: 1, b: 3} + let newColl = i.assoc(coll, "b", 3); // {a: 1, b: 3} let arr = ["a", "b", "c"]; let newArr = i.assoc(arr, 2, "d"); // ["a", "b", "d"] @@ -36,7 +36,7 @@ class Foo {} // alias: set(collection, key, value) { let coll = { a: 1, b: 2 }; - let newColl = i.set(coll, "b", 3); // {a: 1, b: 3} + let newColl = i.set(coll, "b", 3); // {a: 1, b: 3} let arr = ["a", "b", "c"]; let newArr = i.set(arr, 2, "d"); // ["a", "b", "d"] @@ -70,7 +70,7 @@ class Foo {} } }; - let newColl = i.assocIn(coll, ["c", "d"], "baz"); + let newColl = i.assocIn(coll, ["c", "d"], "baz"); let coll2 = {}; let newColl2 = i.assocIn(coll2, ["a", "b", "c"], 1); @@ -86,7 +86,7 @@ class Foo {} } }; - let newColl = i.setIn(coll, ["c", "d"], "baz"); + let newColl = i.setIn(coll, ["c", "d"], "baz"); let coll2 = {}; let newColl2 = i.setIn(coll2, ["a", "b", "c"], 1); @@ -99,7 +99,7 @@ class Foo {} { b: 2 } ]); - let result = i.getIn(coll, [1, "b"]); // 2 + let result = i.getIn(coll, [1, "b"]) as number; // 2 } // updateIn(collection, path, callback) @@ -166,9 +166,13 @@ class Foo {} }; let result = i.chain(o) - .assocIn(["a", 2], 4) + .assocIn(["a", 2], 4) + .setIn(["a", 1], 5) + .updateIn(["d"], function(d) { return d * 2 }) .merge({ b: { c: 2, c2: 3 } }) - .assoc("e", 2) + .assoc("e", 2) + .set("f", 3) .dissoc("d") - .value(); + .getIn(['a', 0]) + .value() as number; } diff --git a/icepick/index.d.ts b/icepick/index.d.ts index 184f0e12b1..bffe424d1b 100644 --- a/icepick/index.d.ts +++ b/icepick/index.d.ts @@ -1,15 +1,15 @@ -// Type definitions for icepick v1.1.0 +// Type definitions for icepick v1.3.0 // Project: https://github.com/aearly/icepick -// Definitions by: Nathan Brown +// Definitions by: Nathan Brown , Tobias Cohen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export declare function freeze(collection: T): T; export declare function thaw(collection: T): T; -export declare function assoc(collection: T, key: number | string, value: any): T; +export declare function assoc(collection: T, key: number | string, value: V): T; export declare function dissoc(collection: T, key: number | string): T; -export declare function assocIn(collection: T, path: Array, value: any): T; -export declare function getIn(collection: any, path: Array): Result; +export declare function assocIn(collection: T, path: Array, value: V): T; +export declare function getIn(collection: T, path: Array): any; export declare function updateIn(collection: T, path: Array, callback: (value: V) => V): T; export {assoc as set}; @@ -44,17 +44,17 @@ interface IcepickWrapper { freeze(): IcepickWrapper; thaw(): IcepickWrapper; - assoc(key: number | string, value: any): IcepickWrapper; - set(key: number | string, value: any): IcepickWrapper; + assoc(key: number | string, value: V): IcepickWrapper; + set(key: number | string, value: V): IcepickWrapper; dissoc(key: number | string): IcepickWrapper; unset(key: number | string): IcepickWrapper; - assocIn(path: Array, value: any): IcepickWrapper; - setIn(path: Array, value: any): IcepickWrapper; + assocIn(path: Array, value: V): IcepickWrapper; + setIn(path: Array, value: V): IcepickWrapper; - getIn(collection: any, path: Array): IcepickWrapper; - updateIn(collection: T, path: Array, callback: (value: V) => V): IcepickWrapper; + getIn(path: Array): IcepickWrapper; + updateIn(path: Array, callback: (value: V) => V): IcepickWrapper; assign(source1: S1): IcepickWrapper; assign(s1: S1, s2: S2): IcepickWrapper;