From da27def5624cdf4768c4595effb529f715a4ae91 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 22 Jul 2015 15:27:43 +0100 Subject: [PATCH 1/3] Add lodash types for chainable contains/include/includes --- lodash/lodash-tests.ts | 15 ++++++++++++ lodash/lodash.d.ts | 53 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 9b4548502..f61ba1573 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -370,16 +370,31 @@ result = _.contains([1, 2, 3], 1, 2); result = _.contains({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40); result = _.contains('curly', 'ur'); +result = _([1, 2, 3]).contains(1); +result = _([1, 2, 3]).contains(1, 2); +result = _({ 'moe': 30, 'larry': 40, 'curly': 67 }).contains(40); +result = _('curly').contains('ur'); + result = _.include([1, 2, 3], 1); result = _.include([1, 2, 3], 1, 2); result = _.include({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40); result = _.include('curly', 'ur'); +result = _([1, 2, 3]).include(1); +result = _([1, 2, 3]).include(1, 2); +result = _({ 'moe': 30, 'larry': 40, 'curly': 67 }).include(40); +result = _('curly').include('ur'); + result = _.includes([1, 2, 3], 1); result = _.includes([1, 2, 3], 1, 2); result = _.includes({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40); result = _.includes('curly', 'ur'); +result = _([1, 2, 3]).includes(1); +result = _([1, 2, 3]).includes(1, 2); +result = _({ 'moe': 30, 'larry': 40, 'curly': 67 }).includes(40); +result = _('curly').includes('ur'); + result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return Math.floor(num); }); result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return this.floor(num); }, Math); result = <_.Dictionary>_.countBy(['one', 'two', 'three'], 'length'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f02a4aa97..d2e83e111 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -39,7 +39,7 @@ declare module _ { * Explicit chaining can be enabled by using the _.chain method. **/ (value: number): LoDashWrapper; - (value: string): LoDashWrapper; + (value: string): LoDashStringWrapper; (value: boolean): LoDashWrapper; (value: Array): LoDashNumberArrayWrapper; (value: Array): LoDashArrayWrapper; @@ -2149,6 +2149,57 @@ declare module _ { fromIndex?: number): boolean; } + interface LoDashArrayWrapper { + /** + * @see _.contains + **/ + contains(target: T, fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + include(target: T, fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + includes(target: T, fromIndex?: number): boolean; + } + + interface LoDashObjectWrapper { + /** + * @see _.contains + **/ + contains(target: any, fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + include(target: any, fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + includes(target: any, fromIndex?: number): boolean; + } + + interface LoDashStringWrapper extends LoDashWrapper { + /** + * @see _.contains + **/ + contains(target: string, fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + include(target: string, fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + includes(target: string, fromIndex?: number): boolean; + } + //_.countBy interface LoDashStatic { /** From a9a55446fc4f5641b9f0c30c439ffbca9fdc0032 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 22 Jul 2015 15:32:15 +0100 Subject: [PATCH 2/3] Make lodash object _().contains type clearer (no any) --- lodash/lodash.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index d2e83e111..d116a2514 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2170,17 +2170,17 @@ declare module _ { /** * @see _.contains **/ - contains(target: any, fromIndex?: number): boolean; + contains(target: TValue, fromIndex?: number): boolean; /** * @see _.contains **/ - include(target: any, fromIndex?: number): boolean; + include(target: TValue, fromIndex?: number): boolean; /** * @see _.contains **/ - includes(target: any, fromIndex?: number): boolean; + includes(target: TValue, fromIndex?: number): boolean; } interface LoDashStringWrapper extends LoDashWrapper { From d9088b29d8093191588cc61c21bdfe5f76648033 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Sun, 26 Jul 2015 16:07:46 +0100 Subject: [PATCH 3/3] Put LoDashStringWrapper interface declaration at the top with the others --- lodash/lodash.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index d116a2514..e73af15b1 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -190,6 +190,8 @@ declare module _ { interface LoDashWrapper extends LoDashWrapperBase> { } + interface LoDashStringWrapper extends LoDashWrapper { } + interface LoDashObjectWrapper extends LoDashWrapperBase> { } interface LoDashArrayWrapper extends LoDashWrapperBase> { @@ -2183,7 +2185,7 @@ declare module _ { includes(target: TValue, fromIndex?: number): boolean; } - interface LoDashStringWrapper extends LoDashWrapper { + interface LoDashStringWrapper { /** * @see _.contains **/