diff --git a/lib/object.d.ts b/lib/object.d.ts index d9f9f64..86a5e2e 100644 --- a/lib/object.d.ts +++ b/lib/object.d.ts @@ -1,3 +1,5 @@ +type PropertyName = string | number | symbol; + /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. @@ -59,7 +61,17 @@ export function get(target: any, path: (string|number)[], defaultValue?: any): a * * @return the element */ -export function set(target: T, path: (string|number)[], value: any): T; +export function set(target: T, path: PropertyName[], value: any): T; + +/** + * Pick properties from the given target. + * + * @param target + * @param properties + * + * @return + */ +export function pick(target: T, properties: Array): Pick; /** * Pick properties from the given target. @@ -69,7 +81,17 @@ export function set(target: T, path: (string|number)[], value: any): T; * * @return */ -export function pick(target: T, properties: V): Pick; +export function pick(target: T, properties: V): Partial; + +/** + * Pick all target properties, excluding the given ones. + * + * @param target + * @param properties + * + * @return target + */ +export function omit(target: T, properties: V): Omit; /** * Pick all target properties, excluding the given ones. @@ -79,7 +101,7 @@ export function pick(target: T, properties: V): Pick; * * @return target */ -export function omit(target: T, properties: V): Omit; +export function omit(target: T, properties: V): Pick>; /** * Copy the values of all of the enumerable own properties from one or more source objects to a diff --git a/test/object.spec.js b/test/object.spec.js index 80b798c..6cb8836 100644 --- a/test/object.spec.js +++ b/test/object.spec.js @@ -36,6 +36,11 @@ describe('object', function() { e: undefined }); + // and when + let otherPicked = pick(obj, [ 'a', 'b' ]); + + // then + expect(otherPicked.a).to.eql(1); });