lodash: signatures of the method _.thru changed

This commit is contained in:
Ilya Mochalov
2015-10-18 20:12:31 +05:00
parent b7a578fbd8
commit 636876145a
2 changed files with 138 additions and 31 deletions

View File

@@ -1188,35 +1188,98 @@ module TestTap {
}
// _.thru
{
let result: number;
result = _.thru<number, number>(1, (value: number) => value);
result = _.thru<number, number>(1, (value: number) => value, any);
}
{
let result: _.LoDashImplicitWrapper<number>;
result = _(1).thru<number>((value: number) => value);
result = _(1).thru<number>((value: number) => value, any);
}
{
let result: _.LoDashImplicitWrapper<string>;
result = _('').thru<string>((value: string) => value);
result = _('').thru<string>((value: string) => value, any);
}
{
let result: _.LoDashImplicitWrapper<boolean>;
result = _(true).thru<boolean>((value: boolean) => value);
result = _(true).thru<boolean>((value: boolean) => value, any);
}
{
let result: _.LoDashImplicitObjectWrapper<any>;
result = _({}).thru<Object>((value: Object) => value);
result = _({}).thru<Object>((value: Object) => value, any);
}
{
let result: _.LoDashImplicitArrayWrapper<number>;
result = _([1, 2, 3]).thru<number>((value: number[]) => value);
result = _([1, 2, 3]).thru<number>((value: number[]) => value, any);
module TestThru {
interface Interceptor<T> {
(value: T): T;
}
{
let interceptor: Interceptor<number>;
let result: number;
result = _.thru<number, number>(1, interceptor);
result = _.thru<number, number>(1, interceptor, any);
}
{
let interceptor: Interceptor<number>;
let result: _.LoDashImplicitWrapper<number>;
result = _(1).thru<number>(interceptor);
result = _(1).thru<number>(interceptor, any);
}
{
let interceptor: Interceptor<string>;
let result: _.LoDashImplicitWrapper<string>;
result = _('').thru<string>(interceptor);
result = _('').thru<string>(interceptor, any);
}
{
let interceptor: Interceptor<boolean>;
let result: _.LoDashImplicitWrapper<boolean>;
result = _(true).thru<boolean>(interceptor);
result = _(true).thru<boolean>(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<number[]>;
let result: _.LoDashImplicitArrayWrapper<number>;
result = _([1, 2, 3]).thru<number>(interceptor);
result = _([1, 2, 3]).thru<number>(interceptor, any);
}
{
let interceptor: Interceptor<number>;
let result: _.LoDashExplicitWrapper<number>;
result = _(1).chain().thru<number>(interceptor);
result = _(1).chain().thru<number>(interceptor, any);
}
{
let interceptor: Interceptor<string>;
let result: _.LoDashExplicitWrapper<string>;
result = _('').chain().thru<string>(interceptor);
result = _('').chain().thru<string>(interceptor, any);
}
{
let interceptor: Interceptor<boolean>;
let result: _.LoDashExplicitWrapper<boolean>;
result = _(true).chain().thru<boolean>(interceptor);
result = _(true).chain().thru<boolean>(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<number[]>;
let result: _.LoDashExplicitArrayWrapper<number>;
result = _([1, 2, 3]).chain().thru<number>(interceptor);
result = _([1, 2, 3]).chain().thru<number>(interceptor, any);
}
}
// _.prototype.commit

48
lodash/lodash.d.ts vendored
View File

@@ -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<T, TResult>(
value: T,
interceptor: (value: T) => TResult,
thisArg?: any): TResult;
thisArg?: any
): TResult;
}
interface LoDashImplicitWrapperBase<T, TWrapper> {
@@ -2413,7 +2415,7 @@ declare module _ {
/**
* @see _.thru
*/
thru<TResult extends Object>(
thru<TResult extends {}>(
interceptor: (value: T) => TResult,
thisArg?: any): LoDashImplicitObjectWrapper<TResult>;
@@ -2425,6 +2427,48 @@ declare module _ {
thisArg?: any): LoDashImplicitArrayWrapper<TResult>;
}
interface LoDashExplicitWrapperBase<T, TWrapper> {
/**
* @see _.thru
*/
thru<TResult extends number>(
interceptor: (value: T) => TResult,
thisArg?: any
): LoDashExplicitWrapper<TResult>;
/**
* @see _.thru
*/
thru<TResult extends string>(
interceptor: (value: T) => TResult,
thisArg?: any
): LoDashExplicitWrapper<TResult>;
/**
* @see _.thru
*/
thru<TResult extends boolean>(
interceptor: (value: T) => TResult,
thisArg?: any
): LoDashExplicitWrapper<TResult>;
/**
* @see _.thru
*/
thru<TResult extends {}>(
interceptor: (value: T) => TResult,
thisArg?: any
): LoDashExplicitObjectWrapper<TResult>;
/**
* @see _.thru
*/
thru<TResult>(
interceptor: (value: T) => TResult[],
thisArg?: any
): LoDashExplicitArrayWrapper<TResult>;
}
// _.prototype.commit
interface LoDashImplicitWrapperBase<T, TWrapper> {
/**