diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 5b9add244c..627fa38f85 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1941,9 +1941,32 @@ result = _.words('fred, barney, & pebbles', /[^, ]+/g); result = _('fred, barney, & pebbles').words(); result = _('fred, barney, & pebbles').words(/[^, ]+/g); -/********** -* Utilities * -***********/ +/*********** + * Utility * + ***********/ + +// _.callback +{ + let result: (...args: any[]) => TResult; + result = _.callback(Function); + result = _.callback(Function, any); + result = _(Function).callback().value(); + result = _(Function).callback(any).value(); +} +{ + let result: (object: any) => TResult; + result = _.callback(''); + result = _.callback('', any); + result = _('').callback().value(); + result = _('').callback(any).value(); +} +{ + let result: (object: any) => boolean; + result = _.callback({}); + result = _.callback({}, any); + result = _({}).callback().value(); + result = _({}).callback(any).value(); +} // _.constant result = <() => number>_.constant(1); @@ -1973,6 +1996,29 @@ result = <() => {}>_({}).constant<{}>(); result = _([]).identity(); } +// _.iteratee +{ + let result: (...args: any[]) => TResult; + result = _.iteratee(Function); + result = _.iteratee(Function, any); + result = _(Function).iteratee().value(); + result = _(Function).iteratee(any).value(); +} +{ + let result: (object: any) => TResult; + result = _.iteratee(''); + result = _.iteratee('', any); + result = _('').iteratee().value(); + result = _('').iteratee(any).value(); +} +{ + let result: (object: any) => boolean; + result = _.iteratee({}); + result = _.iteratee({}, any); + result = _({}).iteratee().value(); + result = _({}).iteratee(any).value(); +} + // _.method class TestMethod { a = { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b6c95710bd..bc9898556f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8117,6 +8117,64 @@ declare module _ { attempt(): TResult|Error; } + //_.callback + interface LoDashStatic { + /** + * Creates a function that invokes func with the this binding of thisArg and arguments of the created function. + * If func is a property name the created callback returns the property value for a given element. If func is + * an object the created callback returns true for elements that contain the equivalent object properties, + * otherwise it returns false. + * + * @param func The value to convert to a callback. + * @param thisArg The this binding of func. + * @result Returns the callback. + */ + callback( + func: Function, + thisArg?: any + ): (...args: any[]) => TResult; + + /** + * @see _.callback + */ + callback( + func: string, + thisArg?: any + ): (object: any) => TResult; + + /** + * @see _.callback + */ + callback( + func: Object, + thisArg?: any + ): (object: any) => boolean; + + /** + * @see _.callback + */ + callback(): (value: TResult) => TResult; + } + + interface LoDashWrapper { + /** + * @see _.callback + */ + callback(thisArg?: any): LoDashObjectWrapper<(object: any) => TResult>; + } + + interface LoDashObjectWrapper { + /** + * @see _.callback + */ + callback(thisArg?: any): LoDashObjectWrapper<(object: any) => boolean>; + + /** + * @see _.callback + */ + callback(thisArg?: any): LoDashObjectWrapper<(...args: any[]) => TResult>; + } + //_.identity interface LoDashStatic { /** @@ -8148,6 +8206,57 @@ declare module _ { identity(): T; } + //_.iteratee + interface LoDashStatic { + /** + * @see _.callback + */ + iteratee( + func: Function, + thisArg?: any + ): (...args: any[]) => TResult; + + /** + * @see _.callback + */ + iteratee( + func: string, + thisArg?: any + ): (object: any) => TResult; + + /** + * @see _.callback + */ + iteratee( + func: Object, + thisArg?: any + ): (object: any) => boolean; + + /** + * @see _.callback + */ + iteratee(): (value: TResult) => TResult; + } + + interface LoDashWrapper { + /** + * @see _.callback + */ + iteratee(thisArg?: any): LoDashObjectWrapper<(object: any) => TResult>; + } + + interface LoDashObjectWrapper { + /** + * @see _.callback + */ + iteratee(thisArg?: any): LoDashObjectWrapper<(object: any) => boolean>; + + /** + * @see _.callback + */ + iteratee(thisArg?: any): LoDashObjectWrapper<(...args: any[]) => TResult>; + } + //_.method interface LoDashStatic { /**