diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 2511ca82c..87e5d9a57 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5812,11 +5812,89 @@ module TestThrottle { } } -var helloWrap = function (name: string) { return 'hello ' + name; }; -var helloWrap2 = _.wrap(helloWrap, function (func) { - return 'before, ' + func('moe') + ', after'; -}); -helloWrap2(); +// _.wrap +module TestWrap { + type SampleValue = {a: number; b: string; c: boolean} + type SampleResult = (arg2: number, arg3: string) => boolean; + + { + type SampleWrapper = (arg1: SampleValue, arg2: number, arg3: string) => boolean; + + let value: SampleValue; + let wrapper: SampleWrapper; + let result: SampleResult; + + result = _.wrap(value, wrapper); + result = _.wrap(value, wrapper); + result = _.wrap(value, wrapper); + } + + { + type SampleWrapper = (arg1: number, arg2: number, arg3: string) => boolean; + + let value: number; + let wrapper: SampleWrapper; + let result: _.LoDashImplicitObjectWrapper; + + result = _(value).wrap(wrapper); + result = _(value).wrap(wrapper); + } + + { + type SampleWrapper = (arg1: number[], arg2: number, arg3: string) => boolean; + + let value: number[]; + let wrapper: SampleWrapper; + let result: _.LoDashImplicitObjectWrapper; + + result = _(value).wrap(wrapper); + result = _(value).wrap(wrapper); + } + + { + type SampleWrapper = (arg1: SampleValue, arg2: number, arg3: string) => boolean; + + let value: SampleValue; + let wrapper: SampleWrapper; + let result: _.LoDashImplicitObjectWrapper; + + result = _(value).wrap(wrapper); + result = _(value).wrap(wrapper); + } + + { + type SampleWrapper = (arg1: number, arg2: number, arg3: string) => boolean; + + let value: number; + let wrapper: SampleWrapper; + let result: _.LoDashExplicitObjectWrapper; + + result = _(value).chain().wrap(wrapper); + result = _(value).chain().wrap(wrapper); + } + + { + type SampleWrapper = (arg1: number[], arg2: number, arg3: string) => boolean; + + let value: number[]; + let wrapper: SampleWrapper; + let result: _.LoDashExplicitObjectWrapper; + + result = _(value).chain().wrap(wrapper); + result = _(value).chain().wrap(wrapper); + } + + { + type SampleWrapper = (arg1: SampleValue, arg2: number, arg3: string) => boolean; + + let value: SampleValue; + let wrapper: SampleWrapper; + let result: _.LoDashExplicitObjectWrapper; + + result = _(value).chain().wrap(wrapper); + result = _(value).chain().wrap(wrapper); + } +} /******** * Lang * diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 9e88673bc..41334d12b 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -9614,16 +9614,106 @@ declare module _ { //_.wrap interface LoDashStatic { /** - * Creates a function that provides value to the wrapper function as its first argument. - * Additional arguments provided to the function are appended to those provided to the - * wrapper function. The wrapper is executed with the this binding of the created function. - * @param value The value to wrap. - * @param wrapper The wrapper function. - * @return The new function. - **/ - wrap( + * Creates a function that provides value to the wrapper function as its first argument. Any additional + * arguments provided to the function are appended to those provided to the wrapper function. The wrapper is + * invoked with the this binding of the created function. + * + * @param value The value to wrap. + * @param wrapper The wrapper function. + * @return Returns the new function. + */ + wrap( + value: V, + wrapper: W + ): R; + + /** + * @see _.wrap + */ + wrap( + value: V, + wrapper: Function + ): R; + + /** + * @see _.wrap + */ + wrap( value: any, - wrapper: (func: Function, ...args: any[]) => any): Function; + wrapper: Function + ): R; + } + + interface LoDashImplicitWrapper { + /** + * @see _.wrap + */ + wrap(wrapper: W): LoDashImplicitObjectWrapper; + + /** + * @see _.wrap + */ + wrap(wrapper: Function): LoDashImplicitObjectWrapper; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.wrap + */ + wrap(wrapper: W): LoDashImplicitObjectWrapper; + + /** + * @see _.wrap + */ + wrap(wrapper: Function): LoDashImplicitObjectWrapper; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.wrap + */ + wrap(wrapper: W): LoDashImplicitObjectWrapper; + + /** + * @see _.wrap + */ + wrap(wrapper: Function): LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitWrapper { + /** + * @see _.wrap + */ + wrap(wrapper: W): LoDashExplicitObjectWrapper; + + /** + * @see _.wrap + */ + wrap(wrapper: Function): LoDashExplicitObjectWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.wrap + */ + wrap(wrapper: W): LoDashExplicitObjectWrapper; + + /** + * @see _.wrap + */ + wrap(wrapper: Function): LoDashExplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.wrap + */ + wrap(wrapper: W): LoDashExplicitObjectWrapper; + + /** + * @see _.wrap + */ + wrap(wrapper: Function): LoDashExplicitObjectWrapper; } /********