diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 5528d67cf1..9062500a9e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -257,37 +257,16 @@ result = _.findLastIndex(['apple', 'banana', 'beet'], function (f: strin result = _.findLastIndex(['apple', 'banana', 'beet'], 'apple'); result = _.findLastIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' }); -result = _.first([1, 2, 3]); -result = _.first([1, 2, 3], 2); -result = _.first([1, 2, 3], function (num) { - return num < 3; -}); -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) { - return num < 3; -}); -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(); +// _.first +module TestFirst { + let array: TResult[]; + let list: _.List; + let result: TResult; + result = _.first(array); + result = _.first(list); + result = _(array).first(); + result = _(list).first(); +} result = _.take([1, 2, 3]); result = _.take([1, 2, 3], 2); @@ -320,6 +299,17 @@ result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flattenDeep(); +// _.head +module TestHead { + let array: TResult[]; + let list: _.List; + let result: TResult; + result = _.head(array); + result = _.head(list); + result = _(array).head(); + result = _(list).head(); +} + result = _.indexOf([1, 2, 3, 1, 2, 3], 2); result = _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); result = _.indexOf([1, 1, 2, 2, 3, 3], 2, true); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f970b13827..6a6291ac07 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -556,162 +556,31 @@ declare module _ { //_.first interface LoDashStatic { /** - * Gets the first element or first n elements of an array. If a callback is provided - * elements at the beginning of the array are returned as long as the callback returns - * truey. The callback is bound to thisArg and invoked with three arguments; (value, - * index, array). - * - * If a property name is provided for callback the created "_.pluck" style callback - * will return the property value of the given element. - * - * If an object is provided for callback the created "_.where" style callback will return ] - * true for elements that have the properties of the given object, else false. - * @param array Retrieves the first element of this array. - * @return Returns the first element of `array`. - **/ - first(array?: Array): T; + * Gets the first element of array. + * + * @alias _.head + * + * @param array The array to query. + * @return Returns the first element of array. + */ + first(array: List): T; + } + interface LoDashArrayWrapper { /** - * @see _.first - **/ - first(array?: List): T; + * @see _.first + */ + first(): T; + } + interface LoDashObjectWrapper { /** - * @see _.first - * @param n The number of elements to return. - **/ - first( - array: Array, - n: number): T[]; - - /** - * @see _.first - * @param n The number of elements to return. - **/ - first( - array: List, - n: number): T[]; - - /** - * @see _.first - * @param callback The function called per element. - * @param [thisArg] The this binding of callback. - **/ - first( - array: Array, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.first - * @param callback The function called per element. - * @param [thisArg] The this binding of callback. - **/ - first( - array: List, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.first - * @param pluckValue "_.pluck" style callback value - **/ - first( - array: Array, - pluckValue: string): T[]; - - /** - * @see _.first - * @param pluckValue "_.pluck" style callback value - **/ - first( - array: List, - pluckValue: string): T[]; - - /** - * @see _.first - * @param whereValue "_.where" style callback value - **/ - first( - array: Array, - whereValue: W): T[]; - - /** - * @see _.first - * @param whereValue "_.where" style callback value - **/ - first( - array: List, - whereValue: W): T[]; - - /** - * @see _.first - **/ - head(array: Array): T; - - /** - * @see _.first - **/ - head(array: List): T; - - /** - * @see _.first - **/ - head( - array: Array, - n: number): T[]; - - /** - * @see _.first - **/ - head( - array: List, - n: number): T[]; - - /** - * @see _.first - **/ - head( - array: Array, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.first - **/ - head( - array: List, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.first - **/ - head( - array: Array, - pluckValue: string): T[]; - - /** - * @see _.first - **/ - head( - array: List, - pluckValue: string): T[]; - - /** - * @see _.first - **/ - head( - array: Array, - whereValue: W): T[]; - - /** - * @see _.first - **/ - head( - array: List, - whereValue: W): T[]; + * @see _.first + */ + first(): TResult; + } + interface LoDashStatic { /** * @see _.first **/ @@ -770,70 +639,6 @@ declare module _ { } 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 **/ @@ -926,6 +731,28 @@ declare module _ { flattenDeep(): LoDashArrayWrapper; } + //_.head + interface LoDashStatic { + /** + * @see _.first + */ + head(array: List): T; + } + + interface LoDashArrayWrapper { + /** + * @see _.first + */ + head(): T; + } + + interface LoDashObjectWrapper { + /** + * @see _.first + */ + head(): TResult; + } + //_.indexOf interface LoDashStatic { /**