From 4a60180d71e2d4759b8099f495950f71e6ea17e7 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Wed, 11 Nov 2015 19:04:19 +0500 Subject: [PATCH] lodash: signatures of the method _.includes have been changed --- lodash/lodash-tests.ts | 156 +++++++++++++++--- lodash/lodash.d.ts | 360 ++++++++++++++++++++++++++--------------- 2 files changed, 358 insertions(+), 158 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 4c587b57b..ddbc61ec3 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -2397,35 +2397,51 @@ module TestCollect { } } -result = _.contains([1, 2, 3], 1); -result = _.contains([1, 2, 3], 1, 2); -result = _.contains({ 'moe': 30, 'larry': 40, 'curly': 67 }, 40); -result = _.contains('curly', 'ur'); +// _.contains +module TestContains { + type SampleType = {a: string; b: number; c: boolean;}; -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'); + let array: SampleType[]; + let list: _.List; + let dictionary: _.Dictionary; -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'); + let target: SampleType; -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'); + { + let result: boolean; -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 = _.contains(array, target); + result = _.contains(array, target, 42); -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 = _.contains(list, target); + result = _.contains(list, target, 42); + + result = _.contains(dictionary, target); + result = _.contains(dictionary, target, 42); + + result = _(array).contains(target); + result = _(array).contains(target, 42); + + result = _(list).contains(target); + result = _(list).contains(target, 42); + + result = _(dictionary).contains(target); + result = _(dictionary).contains(target, 42); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(array).chain().contains(target); + result = _(array).chain().contains(target, 42); + + result = _(list).chain().contains(target); + result = _(list).chain().contains(target, 42); + + result = _(dictionary).chain().contains(target); + result = _(dictionary).chain().contains(target, 42); + } +} 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); @@ -3034,6 +3050,98 @@ result = <_.Dictionary>_({ prop1: 4.2, prop2: 6.1, prop3: 6.4}).groupB result = <_.Dictionary>_({ prop1: 4.2, prop2: 6.1, prop3: 6.4}).groupBy(function (num) { return this.floor(num); }, Math).value(); result = <_.Dictionary>_({ prop1: 'one', prop2: 'two', prop3: 'three'}).groupBy('length').value(); +// _.include +module TestInclude { + type SampleType = {a: string; b: number; c: boolean;}; + + let array: SampleType[]; + let list: _.List; + let dictionary: _.Dictionary; + + let target: SampleType; + + { + let result: boolean; + + result = _.include(array, target); + result = _.include(array, target, 42); + + result = _.include(list, target); + result = _.include(list, target, 42); + + result = _.include(dictionary, target); + result = _.include(dictionary, target, 42); + + result = _(array).include(target); + result = _(array).include(target, 42); + + result = _(list).include(target); + result = _(list).include(target, 42); + + result = _(dictionary).include(target); + result = _(dictionary).include(target, 42); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(array).chain().include(target); + result = _(array).chain().include(target, 42); + + result = _(list).chain().include(target); + result = _(list).chain().include(target, 42); + + result = _(dictionary).chain().include(target); + result = _(dictionary).chain().include(target, 42); + } +} + +// _.includes +module TestIncludes { + type SampleType = {a: string; b: number; c: boolean;}; + + let array: SampleType[]; + let list: _.List; + let dictionary: _.Dictionary; + + let target: SampleType; + + { + let result: boolean; + + result = _.includes(array, target); + result = _.includes(array, target, 42); + + result = _.includes(list, target); + result = _.includes(list, target, 42); + + result = _.includes(dictionary, target); + result = _.includes(dictionary, target, 42); + + result = _(array).includes(target); + result = _(array).includes(target, 42); + + result = _(list).includes(target); + result = _(list).includes(target, 42); + + result = _(dictionary).includes(target); + result = _(dictionary).includes(target, 42); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(array).chain().includes(target); + result = _(array).chain().includes(target, 42); + + result = _(list).chain().includes(target); + result = _(list).chain().includes(target, 42); + + result = _(dictionary).chain().includes(target); + result = _(dictionary).chain().includes(target, 42); + } +} + result = <_.Dictionary>_.indexBy(keys, 'dir'); result = <_.Dictionary>_.indexBy(keys, function (key) { return String.fromCharCode(key.code); }); result = <_.Dictionary>_.indexBy(keys, function (key) { this.fromCharCode(key.code); }, String); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 98d8bf55d..e36fac421 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -3772,160 +3772,82 @@ declare module _ { //_.contains interface LoDashStatic { /** - * Checks if a given value is present in a collection using strict equality for comparisons, - * i.e. ===. If fromIndex is negative, it is used as the offset from the end of the collection. - * @param collection The collection to iterate over. - * @param target The value to check for. - * @param fromIndex The index to search from. - * @return True if the target element is found, else false. - **/ + * @see _.includes + */ contains( - collection: Array, + collection: List|Dictionary, target: T, - fromIndex?: number): boolean; + fromIndex?: number + ): boolean; /** - * @see _.contains - **/ - contains( - collection: List, - target: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - * @param dictionary The dictionary to iterate over. - * @param value The value in the dictionary to search for. - **/ - contains( - dictionary: Dictionary, - value: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - * @param searchString the string to search - * @param targetString the string to search for - **/ + * @see _.includes + */ contains( - searchString: string, - targetString: string, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - include( - collection: Array, - target: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - include( - collection: List, - target: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - include( - dictionary: Dictionary, - value: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - include( - searchString: string, - targetString: string, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - includes( - collection: Array, - target: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - includes( - collection: List, - target: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - includes( - dictionary: Dictionary, - value: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - includes( - searchString: string, - targetString: string, - fromIndex?: number): boolean; + collection: string, + target: string, + fromIndex?: number + ): boolean; } interface LoDashImplicitArrayWrapper { /** - * @see _.contains - **/ - contains(target: T, fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - include(target: T, fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - includes(target: T, fromIndex?: number): boolean; + * @see _.includes + */ + contains( + target: T, + fromIndex?: number + ): boolean; } interface LoDashImplicitObjectWrapper { /** - * @see _.contains - **/ - contains(target: TValue, fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - include(target: TValue, fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - includes(target: TValue, fromIndex?: number): boolean; + * @see _.includes + */ + contains( + target: TValue, + fromIndex?: number + ): boolean; } - interface LoDashImplicitStringWrapper { + interface LoDashImplicitWrapper { /** - * @see _.contains - **/ - contains(target: string, fromIndex?: number): boolean; + * @see _.includes + */ + contains( + target: string, + fromIndex?: number + ): boolean; + } + interface LoDashExplicitArrayWrapper { /** - * @see _.contains - **/ - include(target: string, fromIndex?: number): boolean; + * @see _.includes + */ + contains( + target: T, + fromIndex?: number + ): LoDashExplicitWrapper; + } + interface LoDashExplicitObjectWrapper { /** - * @see _.contains - **/ - includes(target: string, fromIndex?: number): boolean; + * @see _.includes + */ + contains( + target: TValue, + fromIndex?: number + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitWrapper { + /** + * @see _.includes + */ + contains( + target: string, + fromIndex?: number + ): LoDashExplicitWrapper; } //_.countBy @@ -5357,6 +5279,176 @@ declare module _ { whereValue: W): _.LoDashImplicitObjectWrapper<_.Dictionary>; } + //_.include + interface LoDashStatic { + /** + * @see _.includes + */ + include( + collection: List|Dictionary, + target: T, + fromIndex?: number + ): boolean; + + /** + * @see _.includes + */ + include( + collection: string, + target: string, + fromIndex?: number + ): boolean; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.includes + */ + include( + target: T, + fromIndex?: number + ): boolean; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.includes + */ + include( + target: TValue, + fromIndex?: number + ): boolean; + } + + interface LoDashImplicitWrapper { + /** + * @see _.includes + */ + include( + target: string, + fromIndex?: number + ): boolean; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.includes + */ + include( + target: T, + fromIndex?: number + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.includes + */ + include( + target: TValue, + fromIndex?: number + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitWrapper { + /** + * @see _.includes + */ + include( + target: string, + fromIndex?: number + ): LoDashExplicitWrapper; + } + + //_.includes + interface LoDashStatic { + /** + * Checks if target is in collection using SameValueZero for equality comparisons. If fromIndex is negative, + * it’s used as the offset from the end of collection. + * + * @alias _.contains, _.include + * + * @param collection The collection to search. + * @param target The value to search for. + * @param fromIndex The index to search from. + * @return True if the target element is found, else false. + */ + includes( + collection: List|Dictionary, + target: T, + fromIndex?: number + ): boolean; + + /** + * @see _.includes + */ + includes( + collection: string, + target: string, + fromIndex?: number + ): boolean; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.includes + */ + includes( + target: T, + fromIndex?: number + ): boolean; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.includes + */ + includes( + target: TValue, + fromIndex?: number + ): boolean; + } + + interface LoDashImplicitWrapper { + /** + * @see _.includes + */ + includes( + target: string, + fromIndex?: number + ): boolean; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.includes + */ + includes( + target: T, + fromIndex?: number + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.includes + */ + includes( + target: TValue, + fromIndex?: number + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitWrapper { + /** + * @see _.includes + */ + includes( + target: string, + fromIndex?: number + ): LoDashExplicitWrapper; + } + //_.indexBy interface LoDashStatic { /**