From 879e47cbe22a3df952ae802a7c5531aed546c72c Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sat, 31 May 2014 00:27:00 -0400 Subject: [PATCH 01/13] Add lodash omit chainable defs --- lodash/lodash-tests.ts | 5 +++++ lodash/lodash.d.ts | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 953d32d37..da60a435d 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -877,6 +877,11 @@ result = _.omit({ 'name': 'moe', 'age': 40 }, ['age']); result = _.omit({ 'name': 'moe', 'age': 40 }, function (value) { return typeof value == 'number'; }); +result = _({ 'name': 'moe', 'age': 40 }).omit('age'); +result = _({ 'name': 'moe', 'age': 40 }).omit(['age']); +result = _({ 'name': 'moe', 'age': 40 }).omit(function (value) { + return typeof value == 'number'; +}); result = _.pairs({ 'moe': 30, 'larry': 40 }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index cf227c25e..c363d6806 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5391,6 +5391,27 @@ declare module _ { thisArg?: any): Omitted; } + interface LoDashObjectWrapper { + /** + * @see _.omit + **/ + omit( + ...keys: string[]): Omitted; + + /** + * @see _.omit + **/ + omit( + keys: string[]): Omitted; + + /** + * @see _.omit + **/ + omit( + callback: ObjectIterator, + thisArg?: any): Omitted; + } + //_.pairs interface LoDashStatic { /** From fee014e7b6321ec508855da114e57d0eaec1f04e Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sat, 31 May 2014 00:36:32 -0400 Subject: [PATCH 02/13] Fix issue with omit chainable definition not returning LoDashObjectWrapper --- lodash/lodash-tests.ts | 6 +++--- lodash/lodash.d.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index da60a435d..8a1170c02 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -877,11 +877,11 @@ result = _.omit({ 'name': 'moe', 'age': 40 }, ['age']); result = _.omit({ 'name': 'moe', 'age': 40 }, function (value) { return typeof value == 'number'; }); -result = _({ 'name': 'moe', 'age': 40 }).omit('age'); -result = _({ 'name': 'moe', 'age': 40 }).omit(['age']); +result = _({ 'name': 'moe', 'age': 40 }).omit('age').value(); +result = _({ 'name': 'moe', 'age': 40 }).omit(['age']).value(); result = _({ 'name': 'moe', 'age': 40 }).omit(function (value) { return typeof value == 'number'; -}); +}).value(); result = _.pairs({ 'moe': 30, 'larry': 40 }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c363d6806..ab579457a 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5396,20 +5396,20 @@ declare module _ { * @see _.omit **/ omit( - ...keys: string[]): Omitted; + ...keys: string[]): LoDashObjectWrapper; /** * @see _.omit **/ omit( - keys: string[]): Omitted; + keys: string[]): LoDashObjectWrapper; /** * @see _.omit **/ omit( callback: ObjectIterator, - thisArg?: any): Omitted; + thisArg?: any): LoDashObjectWrapper; } //_.pairs From d5754766b6bebe5952ebb35bf8e11fb2ced1f7b8 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 1 Jun 2014 21:16:30 -0400 Subject: [PATCH 03/13] Add chainable definitions for _(...).pairs --- lodash/lodash-tests.ts | 1 + lodash/lodash.d.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 8a1170c02..8a5df5676 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -884,6 +884,7 @@ result = _({ 'name': 'moe', 'age': 40 }).omit(function (value) { }).value(); result = _.pairs({ 'moe': 30, 'larry': 40 }); +result = _({ 'moe': 30, 'larry': 40 }).pairs().value(); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name'); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, ['name']); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index ab579457a..a05d1d68b 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5423,6 +5423,13 @@ declare module _ { pairs(object: any): any[][]; } + interface LoDashObjectWrapper { + /** + * @see _.pairs + **/ + pairs(): LoDashArrayWrapper; + } + //_.picks interface LoDashStatic { /** From 6e70ecce98a5eff78dc0a5beca7857c4addbeaf0 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 10:08:26 -0400 Subject: [PATCH 04/13] Added chainable definition for _(...).reduce and aliases. --- lodash/lodash-tests.ts | 31 ++++++++++++-- lodash/lodash.d.ts | 94 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 3 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 8a5df5676..7fbbcf3c6 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -420,15 +420,16 @@ result = _.min(stoogesAges, 'age'); result = _.pluck(stoogesAges, 'name'); -result = _.reduce([1, 2, 3], function (sum: number, num: number) { - return sum + num; -}); interface ABC { [index: string]: number; a: number; b: number; c: number; } + +result = _.reduce([1, 2, 3], function (sum: number, num: number) { + return sum + num; +}); result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num: number, key: string) { r[key] = num * 3; return r; @@ -450,6 +451,30 @@ result = _.inject({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num: number return r; }, {}); +result = _([1, 2, 3]).reduce(function (sum: number, num: number) { + return sum + num; +}); +result = _({ 'a': 1, 'b': 2, 'c': 3 }).reduce(function (r: ABC, num: number, key: string) { + r[key] = num * 3; + return r; +}, {}); + +result = _([1, 2, 3]).foldl(function (sum: number, num: number) { + return sum + num; +}); +result = _({ 'a': 1, 'b': 2, 'c': 3 }).foldl(function (r: ABC, num: number, key: string) { + r[key] = num * 3; + return r; +}, {}); + +result = _([1, 2, 3]).inject(function (sum: number, num: number) { + return sum + num; +}); +result = _({ 'a': 1, 'b': 2, 'c': 3 }).inject(function (r: ABC, num: number, key: string) { + r[key] = num * 3; + return r; +}, {}); + result = _.reduceRight([[0, 1], [2, 3], [4, 5]], function (a: number[], b: number[]) { return a.concat(b); }, []); result = _.foldr([[0, 1], [2, 3], [4, 5]], function (a: number[], b: number[]) { return a.concat(b); }, []); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index a05d1d68b..4cfeea09a 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -3609,6 +3609,100 @@ declare module _ { thisArg?: any): TResult; } + interface LoDashArrayWrapper { + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + thisArg?: any): TResult; + } + + interface LoDashObjectWrapper { + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + thisArg?: any): TResult; + } + //_.reduceRight interface LoDashStatic { /** From 4a64d7cdf002adfa2d660d7d21f5a0ef3dc879b5 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 10:19:05 -0400 Subject: [PATCH 05/13] Added chainable definitions for _(...).pluck --- lodash/lodash-tests.ts | 1 + lodash/lodash.d.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 7fbbcf3c6..9438b18fc 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -419,6 +419,7 @@ result = _.min(stoogesAges, function (stooge) { return stooge.age; result = _.min(stoogesAges, 'age'); result = _.pluck(stoogesAges, 'name'); +result = _(stoogesAges).pluck('name').value(); interface ABC { [index: string]: number; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 4cfeea09a..ab4fdd02a 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -3444,6 +3444,22 @@ declare module _ { property: string): any[]; } + interface LoDashArrayWrapper { + /** + * @see _.pluck + **/ + pluck( + property: string): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.pluck + **/ + pluck( + property: string): LoDashArrayWrapper; + } + //_.reduce interface LoDashStatic { /** From 063c99482a5db0609a9a8349e112071561158b8e Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 10:56:47 -0400 Subject: [PATCH 06/13] Added chainable definition for _(...).uniq and aliases --- lodash/lodash-tests.ts | 16 +++++++ lodash/lodash.d.ts | 100 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 9438b18fc..a4b46fb6c 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -277,6 +277,22 @@ result = _.unique(['A', 'b', 'C', 'a', 'B', 'c'], function (letter) { result = _.unique([1, 2.5, 3, 1.5, 2, 3.5], function (num) { return this.floor(num); }, Math); result = <{ x: number; }[]>_.unique([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); +result = _([1, 2, 1, 3, 1]).uniq().value(); +result = _([1, 1, 2, 2, 3]).uniq(true).value(); +result = _(['A', 'b', 'C', 'a', 'B', 'c']).uniq(function (letter) { + return letter.toLowerCase(); +}).value(); +result = _([1, 2.5, 3, 1.5, 2, 3.5]).uniq(function (num) { return this.floor(num); }, Math).value(); +result = <{ x: number; }[]>_([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }]).uniq('x').value(); + +result = _([1, 2, 1, 3, 1]).unique().value(); +result = _([1, 1, 2, 2, 3]).unique(true).value(); +result = _(['A', 'b', 'C', 'a', 'B', 'c']).unique(function (letter) { + return letter.toLowerCase(); +}).value(); +result = _([1, 2.5, 3, 1.5, 2, 3.5]).unique(function (num) { return this.floor(num); }, Math).value(); +result = <{ x: number; }[]>_([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }]).unique('x').value(); + result = _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); result = _.zip(['moe', 'larry'], [30, 40], [true, false]); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index ab4fdd02a..1c3f88155 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1750,6 +1750,106 @@ declare module _ { whereValue?: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.uniq + **/ + uniq(isSorted?: boolean): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + uniq( + isSorted: boolean, + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + uniq( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + uniq( + isSorted: boolean, + pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + uniq(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + uniq( + isSorted: boolean, + whereValue: W): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + uniq( + whereValue: W): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + unique(isSorted?: boolean): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + unique( + isSorted: boolean, + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + unique( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique( + isSorted: boolean, + pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + isSorted: boolean, + whereValue: W): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + whereValue: W): LoDashArrayWrapper; + } + //_.without interface LoDashStatic { /** From 0fad808e8d8d163ab22df42d6469f4e01ddd0c1e Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 16:41:45 -0400 Subject: [PATCH 07/13] Added TResult generic to chainable _(...).pluck methods This is needed because there is no way to cast the output in the middle of the chain. This is not be done on _.pluck() methods because T cannot be inferred. In other words, this: _.pluck(objectArray, 'id'); or this: var id: number = _.pluck(objectArray, 'id'); is cleaner than this: _.pluck(objectArray, 'id'); --- lodash/lodash.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 1c3f88155..8d373d993 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -3548,16 +3548,16 @@ declare module _ { /** * @see _.pluck **/ - pluck( - property: string): LoDashArrayWrapper; + pluck( + property: string): LoDashArrayWrapper; } interface LoDashObjectWrapper { /** * @see _.pluck **/ - pluck( - property: string): LoDashArrayWrapper; + pluck( + property: string): LoDashArrayWrapper; } //_.reduce From be19adcd824538206792b6cb664d93e41f6b3d8f Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 21:58:20 -0400 Subject: [PATCH 08/13] Added chainable definitions for _(...).reject --- lodash/lodash-tests.ts | 4 ++++ lodash/lodash.d.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index a4b46fb6c..c36e211c2 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -499,6 +499,10 @@ result = _.reject([1, 2, 3, 4, 5, 6], function (num) { return num % 2 result = _.reject(foodsCombined, 'organic'); result = _.reject(foodsCombined, { 'type': 'fruit' }); +result = _([1, 2, 3, 4, 5, 6]).reject(function (num) { return num % 2 == 0; }).value(); +result = _(foodsCombined).reject('organic').value(); +result = _(foodsCombined).reject({ 'type': 'fruit' }).value(); + result = _.sample([1, 2, 3, 4]); result = _.sample([1, 2, 3, 4], 2); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 8d373d993..c3089b06a 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -4016,6 +4016,27 @@ declare module _ { whereValue: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.reject + **/ + reject( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.reject + * @param pluckValue _.pluck style callback + **/ + reject(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.reject + * @param whereValue _.where style callback + **/ + reject(whereValue: W): LoDashArrayWrapper; + } + //_.sample interface LoDashStatic { /** From b599ab50cc762e76004fcfed82174dfea62cf927 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 22:06:58 -0400 Subject: [PATCH 09/13] Added chainable definitions for _(...).sortBy --- lodash/lodash-tests.ts | 4 ++++ lodash/lodash.d.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c36e211c2..c9c37c433 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -524,6 +524,10 @@ result = _.sortBy([1, 2, 3], function (num) { return Math.sin(num); }) result = _.sortBy([1, 2, 3], function (num) { return this.sin(num); }, Math); result = _.sortBy(['banana', 'strawberry', 'apple'], 'length'); +result = _([1, 2, 3]).sortBy(function (num) { return Math.sin(num); }).value(); +result = _([1, 2, 3]).sortBy(function (num) { return this.sin(num); }, Math).value(); +result = _(['banana', 'strawberry', 'apple']).sortBy('length').value(); + (function (a: number, b: number, c: number, d: number) { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); result = _.where(stoogesCombined, { 'age': 40 }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c3089b06a..e355330a0 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -4349,6 +4349,27 @@ declare module _ { whereValue: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.sortBy + **/ + sortBy( + callback?: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.sortBy + * @param pluckValue _.pluck style callback + **/ + sortBy(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.sortBy + * @param whereValue _.where style callback + **/ + sortBy(whereValue: W): LoDashArrayWrapper; + } + //_.toArray interface LoDashStatic { /** From f100b9e970120cac097ec5edb4c3646a3b318048 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 22:18:12 -0400 Subject: [PATCH 10/13] Added chainable definitions for _(...).where --- lodash/lodash-tests.ts | 3 +++ lodash/lodash.d.ts | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c9c37c433..6ee7ad464 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -533,6 +533,9 @@ result = _(['banana', 'strawberry', 'apple']).sortBy('length').value() result = _.where(stoogesCombined, { 'age': 40 }); result = _.where(stoogesCombined, { 'quotes': ['Poifect!'] }); +result = _(stoogesCombined).where({ 'age': 40 }).value(); +result = _(stoogesCombined).where({ 'quotes': ['Poifect!'] }).value(); + /************* * Functions * *************/ diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e355330a0..053787bd8 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -4418,6 +4418,13 @@ declare module _ { properties: U): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.where + **/ + where(properties: U): LoDashArrayWrapper; + } + /************* * Functions * *************/ From 5968a6823b92a16a778e62946bee3a4d9d73e503 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 22:40:45 -0400 Subject: [PATCH 11/13] Added chainable definitions for _(...).first and aliases --- lodash/lodash-tests.ts | 24 +++++++++++ lodash/lodash.d.ts | 98 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 6ee7ad464..1836d459e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -183,6 +183,14 @@ result = _.first([1, 2, 3], function (num) { result = _.first(foodsOrganic, 'organic'); result = _.first(foodsType, { 'type': 'fruit' }); +result = _([1, 2, 3]).first(); +result = _([1, 2, 3]).first(2).value(); +result = _([1, 2, 3]).first(function (num) { + return num < 3; +}).value(); +result = _(foodsOrganic).first('organic').value(); +result = _(foodsType).first({ 'type': 'fruit' }).value(); + result = _.head([1, 2, 3]); result = _.head([1, 2, 3], 2); result = _.head([1, 2, 3], function (num) { @@ -191,12 +199,28 @@ result = _.head([1, 2, 3], function (num) { result = _.head(foodsOrganic, 'organic'); result = _.head(foodsType, { 'type': 'fruit' }); +result = _([1, 2, 3]).head(); +result = _([1, 2, 3]).head(2).value(); +result = _([1, 2, 3]).head(function (num) { + return num < 3; +}).value(); +result = _(foodsOrganic).head('organic').value(); +result = _(foodsType).head({ 'type': 'fruit' }).value(); + result = _.take([1, 2, 3]); result = _.take([1, 2, 3], 2); result = _.take([1, 2, 3], (num) => num < 3); result = _.take(foodsOrganic, 'organic'); result = _.take(foodsType, { 'type': 'fruit' }); +result = _([1, 2, 3]).take(); +result = _([1, 2, 3]).take(2).value(); +result = _([1, 2, 3]).take(function (num) { + return num < 3; +}).value(); +result = _(foodsOrganic).take('organic').value(); +result = _(foodsType).take({ 'type': 'fruit' }).value(); + result = _.flatten([1, [2], [3, [[4]]]]); result = _.flatten([1, [2], [3, [[4]]]], true); var result: any diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 053787bd8..2a599cdf3 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -644,6 +644,104 @@ declare module _ { whereValue: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.first + **/ + first(): T; + + /** + * @see _.first + * @param n The number of elements to return. + **/ + first(n: number): LoDashArrayWrapper; + + /** + * @see _.first + * @param callback The function called per element. + * @param [thisArg] The this binding of callback. + **/ + first( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.first + * @param pluckValue "_.pluck" style callback value + **/ + first(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.first + * @param whereValue "_.where" style callback value + **/ + first(whereValue: W): LoDashArrayWrapper; + + /** + * @see _.first + **/ + head(): T; + + /** + * @see _.first + * @param n The number of elements to return. + **/ + head(n: number): LoDashArrayWrapper; + + /** + * @see _.first + * @param callback The function called per element. + * @param [thisArg] The this binding of callback. + **/ + head( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.first + * @param pluckValue "_.pluck" style callback value + **/ + head(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.first + * @param whereValue "_.where" style callback value + **/ + head(whereValue: W): LoDashArrayWrapper; + + /** + * @see _.first + **/ + take(): T; + + /** + * @see _.first + * @param n The number of elements to return. + **/ + take(n: number): LoDashArrayWrapper; + + /** + * @see _.first + * @param callback The function called per element. + * @param [thisArg] The this binding of callback. + **/ + take( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.first + * @param pluckValue "_.pluck" style callback value + **/ + take(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.first + * @param whereValue "_.where" style callback value + **/ + take(whereValue: W): LoDashArrayWrapper; + } + //_.flatten interface LoDashStatic { /** From 1def2150e239b61e30ef391eb06f6761babde888 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Tue, 3 Jun 2014 13:23:28 -0400 Subject: [PATCH 12/13] Add chainable definitions for _(...).keys --- lodash/lodash-tests.ts | 1 + lodash/lodash.d.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 1836d459e..fb56a0b1e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -909,6 +909,7 @@ result = _.isString('moe'); result = _.isUndefined(void 0); result = _.keys({ 'one': 1, 'two': 2, 'three': 3 }); +result = _({ 'one': 1, 'two': 2, 'three': 3 }).keys().value(); var mergeNames = { 'stooges': [ diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 2a599cdf3..482742bed 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5637,6 +5637,13 @@ declare module _ { keys(object: any): string[]; } + interface LoDashObjectWrapper { + /** + * @see _.keys + **/ + keys(): LoDashArrayWrapper + } + //_.mapValues interface LoDashStatic { /** From 79e22825d5bb9d567405bd4d01611850e7aa6f79 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Tue, 3 Jun 2014 13:23:53 -0400 Subject: [PATCH 13/13] Add chainable definitions for _(...).forEach and aliases when passing an non-dictionary object. --- lodash/lodash-tests.ts | 2 ++ lodash/lodash.d.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index fb56a0b1e..e95658916 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -397,9 +397,11 @@ result = _.findLast(foodsCombined, 'organic'); result = _.forEach([1, 2, 3], function (num) { console.log(num); }); result = <_.Dictionary>_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); +result = _.forEach({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) }); result = _.each([1, 2, 3], function (num) { console.log(num); }); result = <_.Dictionary>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); +result = _.each({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) }); result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEach(function (num) { console.log(num); }); result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEach(function (num) { console.log(num); }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 482742bed..ff8502c16 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2939,6 +2939,14 @@ declare module _ { callback: ObjectIterator, thisArg?: any): Dictionary; + /** + * @see _.each + **/ + forEach( + object: T, + callback: ObjectIterator, + thisArg?: any): T + /** * @see _.forEach **/ @@ -2965,6 +2973,14 @@ declare module _ { object: Dictionary, callback: ObjectIterator, thisArg?: any): Dictionary; + + /** + * @see _.each + **/ + each( + object: T, + callback: ObjectIterator, + thisArg?: any): T } interface LoDashArrayWrapper {