diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index d1d53c225..eb08e7c68 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1188,35 +1188,98 @@ module TestTap { } // _.thru -{ - let result: number; - result = _.thru(1, (value: number) => value); - result = _.thru(1, (value: number) => value, any); -} -{ - let result: _.LoDashImplicitWrapper; - result = _(1).thru((value: number) => value); - result = _(1).thru((value: number) => value, any); -} -{ - let result: _.LoDashImplicitWrapper; - result = _('').thru((value: string) => value); - result = _('').thru((value: string) => value, any); -} -{ - let result: _.LoDashImplicitWrapper; - result = _(true).thru((value: boolean) => value); - result = _(true).thru((value: boolean) => value, any); -} -{ - let result: _.LoDashImplicitObjectWrapper; - result = _({}).thru((value: Object) => value); - result = _({}).thru((value: Object) => value, any); -} -{ - let result: _.LoDashImplicitArrayWrapper; - result = _([1, 2, 3]).thru((value: number[]) => value); - result = _([1, 2, 3]).thru((value: number[]) => value, any); +module TestThru { + interface Interceptor { + (value: T): T; + } + + { + let interceptor: Interceptor; + let result: number; + + result = _.thru(1, interceptor); + result = _.thru(1, interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashImplicitWrapper; + + result = _(1).thru(interceptor); + result = _(1).thru(interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashImplicitWrapper; + + result = _('').thru(interceptor); + result = _('').thru(interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashImplicitWrapper; + + result = _(true).thru(interceptor); + result = _(true).thru(interceptor, any); + } + + { + let interceptor: Interceptor<{a: string}>; + let result: _.LoDashImplicitObjectWrapper<{a: string}>; + + result = _({a: ''}).thru<{a: string}>(interceptor); + result = _({a: ''}).thru<{a: string}>(interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashImplicitArrayWrapper; + + result = _([1, 2, 3]).thru(interceptor); + result = _([1, 2, 3]).thru(interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashExplicitWrapper; + + result = _(1).chain().thru(interceptor); + result = _(1).chain().thru(interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashExplicitWrapper; + + result = _('').chain().thru(interceptor); + result = _('').chain().thru(interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashExplicitWrapper; + + result = _(true).chain().thru(interceptor); + result = _(true).chain().thru(interceptor, any); + } + + { + let interceptor: Interceptor<{a: string}>; + let result: _.LoDashExplicitObjectWrapper<{a: string}>; + + result = _({a: ''}).chain().thru<{a: string}>(interceptor); + result = _({a: ''}).chain().thru<{a: string}>(interceptor, any); + } + + { + let interceptor: Interceptor; + let result: _.LoDashExplicitArrayWrapper; + + result = _([1, 2, 3]).chain().thru(interceptor); + result = _([1, 2, 3]).chain().thru(interceptor, any); + } } // _.prototype.commit diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 68aefccc3..ae2996699 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2377,6 +2377,7 @@ declare module _ { interface LoDashStatic { /** * This method is like _.tap except that it returns the result of interceptor. + * * @param value The value to provide to interceptor. * @param interceptor The function to invoke. * @param thisArg The this binding of interceptor. @@ -2385,7 +2386,8 @@ declare module _ { thru( value: T, interceptor: (value: T) => TResult, - thisArg?: any): TResult; + thisArg?: any + ): TResult; } interface LoDashImplicitWrapperBase { @@ -2413,7 +2415,7 @@ declare module _ { /** * @see _.thru */ - thru( + thru( interceptor: (value: T) => TResult, thisArg?: any): LoDashImplicitObjectWrapper; @@ -2425,6 +2427,48 @@ declare module _ { thisArg?: any): LoDashImplicitArrayWrapper; } + interface LoDashExplicitWrapperBase { + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.thru + */ + thru( + interceptor: (value: T) => TResult[], + thisArg?: any + ): LoDashExplicitArrayWrapper; + } + // _.prototype.commit interface LoDashImplicitWrapperBase { /**