mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[lodash] improved iteratee parameters, simplified forEach and flatMap overloads (#18663)
* [lodash] improved iterateee parameters, simplified forEach overloads * Changed ListIterator to StringIterator, cleaned up more issues with flatMap * Even more flatMap cleanup * Fixed type inference for forEach callback arguments
This commit is contained in:
849
types/lodash/index.d.ts
vendored
849
types/lodash/index.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@@ -722,6 +722,7 @@ namespace TestFindIndex {
|
||||
result = _.findIndex<TResult>(list, '');
|
||||
result = _.findIndex<{a: number}, TResult>(list, {a: 42});
|
||||
result = _.findIndex<TResult>(list, predicateFn, fromIndex);
|
||||
result = _.findIndex([{ b: 5 }], ['b', 5]);
|
||||
|
||||
result = _<TResult>(array).findIndex();
|
||||
result = _<TResult>(array).findIndex(predicateFn);
|
||||
@@ -775,6 +776,7 @@ namespace TestFindLastIndex {
|
||||
result = _.findLastIndex<TResult>(list, '');
|
||||
result = _.findLastIndex<{a: number}, TResult>(list, {a: 42});
|
||||
result = _.findLastIndex<TResult>(list, predicateFn, fromIndex);
|
||||
result = _.findLastIndex([{ b: 5 }], ['b', 5]);
|
||||
|
||||
result = _<TResult>(array).findLastIndex();
|
||||
result = _<TResult>(array).findLastIndex(predicateFn);
|
||||
@@ -3449,8 +3451,7 @@ namespace TestEach {
|
||||
let dictionary: _.Dictionary<TResult> = {};
|
||||
let nilArray: TResult[] | null | undefined = [] as any;
|
||||
let nilList: _.List<TResult> | null | undefined = [] as any;
|
||||
let obj: any = {};
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = obj;
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = any;
|
||||
|
||||
let stringIterator: (char: string, index: number, string: string) => any = (char: string, index: number, string: string) => 1;
|
||||
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any = (value: TResult, index: number, collection: _.List<TResult>) => 1;
|
||||
@@ -3471,37 +3472,37 @@ namespace TestEach {
|
||||
{
|
||||
let result: TResult[];
|
||||
|
||||
result = _.each<TResult>(array, listIterator);
|
||||
result = _.each(array, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: TResult[] | null | undefined;
|
||||
|
||||
result = _.each<TResult>(nilArray, listIterator);
|
||||
result = _.each(nilArray, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult>;
|
||||
|
||||
result = _.each<TResult>(list, listIterator);
|
||||
result = _.each(list, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult> | null | undefined;
|
||||
|
||||
result = _.each<TResult>(nilList, listIterator);
|
||||
result = _.each(nilList, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult | null | undefined>;
|
||||
|
||||
result = _.each<TResult>(dictionary, dictionaryIterator);
|
||||
result = _.each(dictionary, dictionaryIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult> | null | undefined;
|
||||
|
||||
result = _.each<TResult>(nilDictionary, dictionaryIterator);
|
||||
result = _.each(nilDictionary, dictionaryIterator);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -3560,8 +3561,7 @@ namespace TestEachRight {
|
||||
let dictionary: _.Dictionary<TResult> = {};
|
||||
let nilArray: TResult[] | null | undefined = [] as any;
|
||||
let nilList: _.List<TResult> | null | undefined = [] as any;
|
||||
let obj: any = {};
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = obj;
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = any;
|
||||
|
||||
let stringIterator: (char: string, index: number, string: string) => any = (char: string, index: number, string: string) => 1;
|
||||
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any = (value: TResult, index: number, collection: _.List<TResult>) => 1;
|
||||
@@ -3582,37 +3582,37 @@ namespace TestEachRight {
|
||||
{
|
||||
let result: TResult[];
|
||||
|
||||
result = _.eachRight<TResult>(array, listIterator);
|
||||
result = _.eachRight(array, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: TResult[] | null | undefined;
|
||||
|
||||
result = _.eachRight<TResult>(nilArray, listIterator);
|
||||
result = _.eachRight(nilArray, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult>;
|
||||
|
||||
result = _.eachRight<TResult>(list, listIterator);
|
||||
result = _.eachRight(list, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult> | null | undefined;
|
||||
|
||||
result = _.eachRight<TResult>(nilList, listIterator);
|
||||
result = _.eachRight(nilList, listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult | null | undefined>;
|
||||
|
||||
result = _.eachRight<TResult>(dictionary, dictionaryIterator);
|
||||
result = _.eachRight(dictionary, dictionaryIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult> | null | undefined;
|
||||
|
||||
result = _.eachRight<TResult>(nilDictionary, dictionaryIterator);
|
||||
result = _.eachRight(nilDictionary, dictionaryIterator);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -3783,16 +3783,19 @@ namespace TestFilter {
|
||||
result = _.filter<TResult>(array, '');
|
||||
result = _.filter<TResult>(array, /./);
|
||||
result = _.filter<TResult>(array, {a: 42});
|
||||
result = _.filter<TResult>(array, ["a", 42]);
|
||||
|
||||
result = _.filter<TResult>(list, listIterator);
|
||||
result = _.filter<TResult>(list, '');
|
||||
result = _.filter<TResult>(list, /./);
|
||||
result = _.filter<TResult>(list, {a: 42});
|
||||
result = _.filter<TResult>(list, ["a", 42]);
|
||||
|
||||
result = _.filter<TResult>(dictionary, dictionaryIterator);
|
||||
result = _.filter<TResult>(dictionary, '');
|
||||
result = _.filter<TResult>(dictionary, /./);
|
||||
result = _.filter<TResult>(dictionary, {a: 42});
|
||||
result = _.filter<TResult>(dictionary, ["a", 42]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -3808,16 +3811,19 @@ namespace TestFilter {
|
||||
result = _(array).filter('');
|
||||
result = _(array).filter(/./);
|
||||
result = _(array).filter({a: 42});
|
||||
result = _(array).filter(["a", 42]);
|
||||
|
||||
result = _(list).filter<TResult>(listIterator);
|
||||
result = _(list).filter<TResult>('');
|
||||
result = _(list).filter<TResult>(/./);
|
||||
result = _(list).filter<TResult>({a: 42});
|
||||
result = _(list).filter<TResult>(["a", 42]);
|
||||
|
||||
result = _(dictionary).filter<TResult>(dictionaryIterator);
|
||||
result = _(dictionary).filter<TResult>('');
|
||||
result = _(dictionary).filter<TResult>(/./);
|
||||
result = _(dictionary).filter<TResult>({a: 42});
|
||||
result = _(dictionary).filter<TResult>(["a", 42]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -3833,16 +3839,32 @@ namespace TestFilter {
|
||||
result = _(array).chain().filter('');
|
||||
result = _(array).chain().filter(/./);
|
||||
result = _(array).chain().filter({a: 42});
|
||||
result = _(array).chain().filter(["a", 42]);
|
||||
|
||||
result = _(list).chain().filter<TResult>(listIterator);
|
||||
result = _(list).chain().filter<TResult>('');
|
||||
result = _(list).chain().filter<TResult>(/./);
|
||||
result = _(list).chain().filter<TResult>({a: 42});
|
||||
result = _(list).chain().filter<TResult>(["a", 42]);
|
||||
|
||||
result = _(dictionary).chain().filter<TResult>(dictionaryIterator);
|
||||
result = _(dictionary).chain().filter<TResult>('');
|
||||
result = _(dictionary).chain().filter<TResult>(/./);
|
||||
result = _(dictionary).chain().filter<TResult>({a: 42});
|
||||
result = _(dictionary).chain().filter<TResult>(["a", 42]);
|
||||
}
|
||||
|
||||
{
|
||||
// Test filtering with type guard
|
||||
let a2: Array<string | number> | null | undefined = any;
|
||||
let d2: _.Dictionary<string | number> | null | undefined = any;
|
||||
|
||||
_.filter(a2, (item: string | number): item is number => typeof item === "number"); // $ExpectType number[]
|
||||
_.filter(d2, (item: string | number): item is number => typeof item === "number"); // $ExpectType number[]
|
||||
_(a2).filter((item: string | number): item is number => typeof item === "number"); // $ExpectType LoDashImplicitArrayWrapper<number>
|
||||
_(d2).filter((item: string | number): item is number => typeof item === "number"); // $ExpectType LoDashImplicitArrayWrapper<number>
|
||||
_(a2).chain().filter((item: string | number): item is number => typeof item === "number"); // $ExpectType LoDashExplicitArrayWrapper<number>
|
||||
_(d2).chain().filter((item: string | number): item is number => typeof item === "number"); // $ExpectType LoDashExplicitArrayWrapper<number>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3858,6 +3880,7 @@ namespace TestFind {
|
||||
|
||||
let result: TResult | undefined;
|
||||
|
||||
result = _.find(array);
|
||||
result = _.find<TResult>(array);
|
||||
result = _.find<TResult>(array, listIterator);
|
||||
result = _.find<TResult>(array, listIterator, 1);
|
||||
@@ -3865,7 +3888,10 @@ namespace TestFind {
|
||||
result = _.find<TResult>(array, '', 1);
|
||||
result = _.find<TResult>(array, {a: 42});
|
||||
result = _.find<TResult>(array, {a: 42}, 1);
|
||||
result = _.find(array, ['a', 5]);
|
||||
result = _.find(array, ['a', 5], 1);
|
||||
|
||||
result = _.find(list);
|
||||
result = _.find<TResult>(list);
|
||||
result = _.find<TResult>(list, listIterator);
|
||||
result = _.find<TResult>(list, listIterator, 1);
|
||||
@@ -3873,7 +3899,10 @@ namespace TestFind {
|
||||
result = _.find<TResult>(list, '', 1);
|
||||
result = _.find<TResult>(list, {a: 42});
|
||||
result = _.find<TResult>(list, {a: 42}, 1);
|
||||
result = _.find(list, ['a', 5]);
|
||||
result = _.find(list, ['a', 5], 1);
|
||||
|
||||
result = _.find(dictionary);
|
||||
result = _.find<TResult>(dictionary);
|
||||
result = _.find<TResult>(dictionary, dictionaryIterator);
|
||||
result = _.find<TResult>(dictionary, dictionaryIterator, 1);
|
||||
@@ -3881,6 +3910,8 @@ namespace TestFind {
|
||||
result = _.find<TResult>(dictionary, '', 1);
|
||||
result = _.find<TResult>(dictionary, {a: 42});
|
||||
result = _.find<TResult>(dictionary, {a: 42}, 1);
|
||||
result = _.find(dictionary, ['a', 5]);
|
||||
result = _.find(dictionary, ['a', 5], 1);
|
||||
|
||||
result = _(array).find();
|
||||
result = _(array).find(listIterator);
|
||||
@@ -3889,6 +3920,8 @@ namespace TestFind {
|
||||
result = _(array).find('', 1);
|
||||
result = _(array).find({a: 42});
|
||||
result = _(array).find({a: 42}, 1);
|
||||
result = _(array).find(['a', 5]);
|
||||
result = _(array).find(['a', 5], 1);
|
||||
|
||||
result = _(list).find<TResult>();
|
||||
result = _(list).find<TResult>(listIterator);
|
||||
@@ -3897,6 +3930,8 @@ namespace TestFind {
|
||||
result = _(list).find<TResult>('', 1);
|
||||
result = _(list).find<TResult>({a: 42});
|
||||
result = _(list).find<TResult>({a: 42}, 1);
|
||||
result = _(list).find<TResult>(['a', 5]);
|
||||
result = _(list).find<TResult>(['a', 5], 1);
|
||||
|
||||
result = _(dictionary).find<TResult>();
|
||||
result = _(dictionary).find<TResult>(dictionaryIterator);
|
||||
@@ -3905,19 +3940,91 @@ namespace TestFind {
|
||||
result = _(dictionary).find<TResult>('', 1);
|
||||
result = _(dictionary).find<TResult>({a: 42});
|
||||
result = _(dictionary).find<TResult>({a: 42}, 1);
|
||||
result = _(dictionary).find<TResult>(['a', 5]);
|
||||
result = _(dictionary).find<TResult>(['a', 5], 1);
|
||||
|
||||
result = _.find([any as TResult, null, undefined], (value: TResult | null | undefined): value is TResult | undefined => value !== null);
|
||||
result = _([any as TResult, null, undefined]).find((value: TResult | null | undefined): value is TResult | undefined => value !== null);
|
||||
}
|
||||
|
||||
result = <number>_.findLast([1, 2, 3, 4], num => num % 2 == 0);
|
||||
result = <IFoodCombined>_.findLast(foodsCombined, { 'type': 'vegetable' });
|
||||
result = <IFoodCombined>_.findLast(foodsCombined, 'organic');
|
||||
// _.findLast
|
||||
namespace TestFindLast {
|
||||
let array: TResult[] | null | undefined = [] as any;
|
||||
let list: _.List<TResult> | null | undefined = [] as any;
|
||||
let obj: any = {};
|
||||
let dictionary: _.Dictionary<TResult> | null | undefined = obj;
|
||||
|
||||
result = <IFoodCombined>_.findLast(foodsCombined, 'organic', 1);
|
||||
let listIterator = (value: TResult, index: number, collection: _.List<TResult>) => true;
|
||||
let dictionaryIterator = (value: TResult, key: string, collection: _.Dictionary<TResult>) => true;
|
||||
|
||||
result = <number>_([1, 2, 3, 4]).findLast(num => num % 2 == 0);
|
||||
result = <IFoodCombined>_(foodsCombined).findLast({ 'type': 'vegetable' });
|
||||
result = <IFoodCombined>_(foodsCombined).findLast('organic');
|
||||
let result: TResult | undefined;
|
||||
|
||||
result = <IFoodCombined>_(foodsCombined).findLast('organic', 1);
|
||||
result = _.findLast(array);
|
||||
result = _.findLast<TResult>(array);
|
||||
result = _.findLast<TResult>(array, listIterator);
|
||||
result = _.findLast<TResult>(array, listIterator, 1);
|
||||
result = _.findLast<TResult>(array, '');
|
||||
result = _.findLast<TResult>(array, '', 1);
|
||||
result = _.findLast<TResult>(array, {a: 42});
|
||||
result = _.findLast<TResult>(array, {a: 42}, 1);
|
||||
result = _.findLast(array, ['a', 5]);
|
||||
result = _.findLast(array, ['a', 5], 1);
|
||||
|
||||
result = _.findLast(list);
|
||||
result = _.findLast<TResult>(list);
|
||||
result = _.findLast<TResult>(list, listIterator);
|
||||
result = _.findLast<TResult>(list, listIterator, 1);
|
||||
result = _.findLast<TResult>(list, '');
|
||||
result = _.findLast<TResult>(list, '', 1);
|
||||
result = _.findLast<TResult>(list, {a: 42});
|
||||
result = _.findLast<TResult>(list, {a: 42}, 1);
|
||||
result = _.findLast(list, ['a', 5]);
|
||||
result = _.findLast(list, ['a', 5], 1);
|
||||
|
||||
result = _.findLast(dictionary);
|
||||
result = _.findLast<TResult>(dictionary);
|
||||
result = _.findLast<TResult>(dictionary, dictionaryIterator);
|
||||
result = _.findLast<TResult>(dictionary, dictionaryIterator, 1);
|
||||
result = _.findLast<TResult>(dictionary, '');
|
||||
result = _.findLast<TResult>(dictionary, '', 1);
|
||||
result = _.findLast<TResult>(dictionary, {a: 42});
|
||||
result = _.findLast<TResult>(dictionary, {a: 42}, 1);
|
||||
result = _.findLast(dictionary, ['a', 5]);
|
||||
result = _.findLast(dictionary, ['a', 5], 1);
|
||||
|
||||
result = _(array).findLast();
|
||||
result = _(array).findLast(listIterator);
|
||||
result = _(array).findLast(listIterator, 1);
|
||||
result = _(array).findLast('');
|
||||
result = _(array).findLast('', 1);
|
||||
result = _(array).findLast({a: 42});
|
||||
result = _(array).findLast({a: 42}, 1);
|
||||
result = _(array).findLast(['a', 5]);
|
||||
result = _(array).findLast(['a', 5], 1);
|
||||
|
||||
result = _(list).findLast<TResult>();
|
||||
result = _(list).findLast<TResult>(listIterator);
|
||||
result = _(list).findLast<TResult>(listIterator, 1);
|
||||
result = _(list).findLast<TResult>('');
|
||||
result = _(list).findLast<TResult>('', 1);
|
||||
result = _(list).findLast<TResult>({a: 42});
|
||||
result = _(list).findLast<TResult>({a: 42}, 1);
|
||||
result = _(list).findLast<TResult>(['a', 5]);
|
||||
result = _(list).findLast<TResult>(['a', 5], 1);
|
||||
|
||||
result = _(dictionary).findLast<TResult>();
|
||||
result = _(dictionary).findLast<TResult>(dictionaryIterator);
|
||||
result = _(dictionary).findLast<TResult>(dictionaryIterator, 1);
|
||||
result = _(dictionary).findLast<TResult>('');
|
||||
result = _(dictionary).findLast<TResult>('', 1);
|
||||
result = _(dictionary).findLast<TResult>({a: 42});
|
||||
result = _(dictionary).findLast<TResult>({a: 42}, 1);
|
||||
result = _(dictionary).findLast<TResult>(['a', 5]);
|
||||
result = _(dictionary).findLast<TResult>(['a', 5], 1);
|
||||
|
||||
result = _.findLast([any as TResult, null, undefined], (value: TResult | null | undefined): value is TResult | undefined => value !== null);
|
||||
result = _([any as TResult, null, undefined]).findLast((value: TResult | null | undefined): value is TResult | undefined => value !== null);
|
||||
}
|
||||
|
||||
// _.flatMap
|
||||
namespace TestFlatMap {
|
||||
@@ -3936,92 +4043,72 @@ namespace TestFlatMap {
|
||||
|
||||
let stringIterator: (value: string, index: number, collection: _.List<string>) => string|string[] = (a, b, c) => "";
|
||||
|
||||
let listIterator: (value: number, index: number, collection: _.List<number|number[]>) => number|number[] = (a, b, c) => 1;
|
||||
let listIterator: (value: number|number[], index: number, collection: _.List<number|number[]>) => number|number[] = (a, b, c) => 1;
|
||||
|
||||
let dictionaryIterator: (value: number, key: number, collection: _.Dictionary<number|number[]>) => number|number[] = (a, b, c) => 1;
|
||||
let dictionaryIterator: (value: number|number[], key: string, collection: _.Dictionary<number|number[]>) => number|number[] = (a, b, c) => 1;
|
||||
|
||||
let numericDictionaryIterator: (value: number, key: number, collection: _.NumericDictionary<number|number[]>) => number|number[] = (a, b, c) => 1;
|
||||
let numericDictionaryIterator: (value: number|number[], key: number, collection: _.NumericDictionary<number|number[]>) => number|number[] = (a, b, c) => 1;
|
||||
|
||||
{
|
||||
let result: string[];
|
||||
|
||||
result = _.flatMap<string>('abc');
|
||||
result = _.flatMap<string>('abc');
|
||||
result = _.flatMap('abc');
|
||||
|
||||
result = _.flatMap<string, string>('abc', stringIterator);
|
||||
result = _.flatMap<string>('abc', stringIterator);
|
||||
result = _.flatMap('abc', stringIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: number[];
|
||||
|
||||
result = _.flatMap<number|number[], number>(numArray);
|
||||
result = _.flatMap(numArray);
|
||||
result = _.flatMap<number>(numArray);
|
||||
|
||||
result = _.flatMap(numArray, listIterator);
|
||||
result = _.flatMap<number|number[], number>(numArray, listIterator);
|
||||
result = _.flatMap<number>(numArray, listIterator);
|
||||
|
||||
result = _.flatMap<({a: number}|{a: number}[])[], number>(objArray, 'a');
|
||||
result = _.flatMap<number>(objArray, 'a');
|
||||
|
||||
result = _.flatMap<number|number[], number>(numList);
|
||||
result = _.flatMap(numList);
|
||||
result = _.flatMap<number>(numList);
|
||||
|
||||
result = _.flatMap(numList, listIterator);
|
||||
result = _.flatMap<number|number[], number>(numList, listIterator);
|
||||
result = _.flatMap<number>(numList, listIterator);
|
||||
|
||||
result = _.flatMap<_.List<{a: number}|{a: number}[]>, number>(objList, 'a');
|
||||
result = _.flatMap<number>(objList, 'a');
|
||||
|
||||
result = _.flatMap<number|number[], number>(numDictionary);
|
||||
result = _.flatMap(numDictionary);
|
||||
result = _.flatMap<number>(numDictionary);
|
||||
|
||||
result = _.flatMap(numDictionary, dictionaryIterator);
|
||||
result = _.flatMap<number|number[], number>(numDictionary, dictionaryIterator);
|
||||
result = _.flatMap<number>(numDictionary, dictionaryIterator);
|
||||
|
||||
result = _.flatMap<_.Dictionary<{a: number}|{a: number}[]>, number>(objDictionary, 'a');
|
||||
result = _.flatMap<number>(objDictionary, 'a');
|
||||
|
||||
result = _.flatMap<number|number[], number>(numNumericDictionary);
|
||||
result = _.flatMap(numNumericDictionary);
|
||||
result = _.flatMap<number>(numNumericDictionary);
|
||||
|
||||
result = _.flatMap(numNumericDictionary, numericDictionaryIterator);
|
||||
result = _.flatMap<number|number[], number>(numNumericDictionary, numericDictionaryIterator);
|
||||
result = _.flatMap<number>(numNumericDictionary, numericDictionaryIterator);
|
||||
|
||||
result = _.flatMap<_.NumericDictionary<{a: number}|{a: number}[]>, number>(objNumericDictionary, 'a');
|
||||
result = _.flatMap<number>(objNumericDictionary, 'a');
|
||||
}
|
||||
|
||||
{
|
||||
let result: boolean[];
|
||||
|
||||
result = _.flatMap<({a: number}|{a: number}[])[], boolean>(objArray, ['a', 42]);
|
||||
result = _.flatMap<boolean>(objArray, ['a', 42]);
|
||||
result = _.flatMap(objArray, ['a', 42]);
|
||||
result = _.flatMap(objArray, {'a': 42});
|
||||
|
||||
result = _.flatMap<{a: number}, ({a: number}|{a: number}[])[]>(objArray, {'a': 42});
|
||||
result = _.flatMap<({a: number}|{a: number}[])[], boolean>(objArray, {'a': 42});
|
||||
result = _.flatMap<boolean>(objArray, {'a': 42});
|
||||
result = _.flatMap(objList, ['a', 42]);
|
||||
result = _.flatMap(objList, {'a': 42});
|
||||
|
||||
result = _.flatMap<_.List<{a: number}|{a: number}[]>, boolean>(objList, ['a', 42]);
|
||||
result = _.flatMap<boolean>(objList, ['a', 42]);
|
||||
result = _.flatMap(objDictionary, ['a', 42]);
|
||||
result = _.flatMap(objDictionary, {'a': 42});
|
||||
|
||||
result = _.flatMap<{a: number}, _.List<{a: number}|{a: number}[]>>(objList, {'a': 42});
|
||||
result = _.flatMap<_.List<{a: number}|{a: number}[]>, boolean>(objList, {'a': 42});
|
||||
result = _.flatMap<boolean>(objList, {'a': 42});
|
||||
|
||||
result = _.flatMap<_.Dictionary<{a: number}|{a: number}[]>, boolean>(objDictionary, ['a', 42]);
|
||||
result = _.flatMap<boolean>(objDictionary, ['a', 42]);
|
||||
|
||||
result = _.flatMap<{a: number}, _.Dictionary<{a: number}|{a: number}[]>>(objDictionary, {'a': 42});
|
||||
result = _.flatMap<_.Dictionary<{a: number}|{a: number}[]>, boolean>(objDictionary, {'a': 42});
|
||||
result = _.flatMap<boolean>(objDictionary, {'a': 42});
|
||||
|
||||
result = _.flatMap<_.NumericDictionary<{a: number}|{a: number}[]>, boolean>(objNumericDictionary, ['a', 42]);
|
||||
result = _.flatMap<boolean>(objNumericDictionary, ['a', 42]);
|
||||
|
||||
result = _.flatMap<{a: number}, _.NumericDictionary<{a: number}|{a: number}[]>>(objNumericDictionary, {'a': 42});
|
||||
result = _.flatMap<_.NumericDictionary<{a: number}|{a: number}[]>, boolean>(objNumericDictionary, {'a': 42});
|
||||
result = _.flatMap<boolean>(objNumericDictionary, {'a': 42});
|
||||
result = _.flatMap(objNumericDictionary, ['a', 42]);
|
||||
result = _.flatMap(objNumericDictionary, {'a': 42});
|
||||
}
|
||||
|
||||
{
|
||||
@@ -4055,16 +4142,16 @@ namespace TestFlatMap {
|
||||
let result: _.LoDashImplicitArrayWrapper<boolean>;
|
||||
|
||||
result = _(objArray).flatMap(['a', 42]);
|
||||
result = _(objArray).flatMap<{a: number}>({a: 42});
|
||||
result = _(objArray).flatMap({a: 42});
|
||||
|
||||
result = _(objList).flatMap(['a', 42]);
|
||||
result = _(objList).flatMap<{a: number}>({a: 42});
|
||||
result = _(objList).flatMap({a: 42});
|
||||
|
||||
result = _(objDictionary).flatMap(['a', 42]);
|
||||
result = _(objDictionary).flatMap<{a: number}>({a: 42});
|
||||
result = _(objDictionary).flatMap({a: 42});
|
||||
|
||||
result = _(objNumericDictionary).flatMap(['a', 42]);
|
||||
result = _(objNumericDictionary).flatMap<{a: number}>({a: 42});
|
||||
result = _(objNumericDictionary).flatMap({a: 42});
|
||||
}
|
||||
|
||||
{
|
||||
@@ -4098,16 +4185,16 @@ namespace TestFlatMap {
|
||||
let result: _.LoDashExplicitArrayWrapper<boolean>;
|
||||
|
||||
result = _(objArray).chain().flatMap(['a', 42]);
|
||||
result = _(objArray).chain().flatMap<{a: number}>({a: 42});
|
||||
result = _(objArray).chain().flatMap({a: 42});
|
||||
|
||||
result = _(objList).chain().flatMap(['a', 42]);
|
||||
result = _(objList).chain().flatMap<{a: number}>({a: 42});
|
||||
result = _(objList).chain().flatMap({a: 42});
|
||||
|
||||
result = _(objDictionary).chain().flatMap(['a', 42]);
|
||||
result = _(objDictionary).chain().flatMap<{a: number}>({a: 42});
|
||||
result = _(objDictionary).chain().flatMap({a: 42});
|
||||
|
||||
result = _(objNumericDictionary).chain().flatMap(['a', 42]);
|
||||
result = _(objNumericDictionary).chain().flatMap<{a: number}>({a: 42});
|
||||
result = _(objNumericDictionary).chain().flatMap({a: 42});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4118,77 +4205,137 @@ namespace TestForEach {
|
||||
let dictionary: _.Dictionary<TResult> = {};
|
||||
let nilArray: TResult[] | null | undefined = [] as any;
|
||||
let nilList: _.List<TResult> | null | undefined = [] as any;
|
||||
let obj: any = {};
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = obj;
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = any;
|
||||
|
||||
let stringIterator: (char: string, index: number, string: string) => any = (char: string, index: number, string: string) => 1;
|
||||
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any = (value: TResult, index: number, collection: _.List<TResult>) => 1;
|
||||
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any = (value: TResult, key: string, collection: _.Dictionary<TResult>) => 1;
|
||||
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any = (value, index, collection) => 1;
|
||||
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any = (value, key, collection) => 1;
|
||||
let objectIterator: (value: number | string | boolean, key: string, collection: TResult) => any = (value, key, collection) => 1;
|
||||
|
||||
{
|
||||
let result: string;
|
||||
|
||||
result = _.forEach('', stringIterator);
|
||||
result = _.forEach('', (value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: string | null | undefined;
|
||||
|
||||
result = _.forEach('' as (string | null | undefined), stringIterator);
|
||||
result = _.forEach('' as (string | null | undefined), (value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: TResult[];
|
||||
|
||||
result = _.forEach<TResult>(array, listIterator);
|
||||
result = _.forEach(array, (value, index, collection: TResult[]) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
});
|
||||
result = _.forEach(array, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
// Note: ideally we'd like collection TResult[], but it seems the best we can get is List<TResult>.
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: TResult[] | null | undefined;
|
||||
|
||||
result = _.forEach<TResult>(nilArray, listIterator);
|
||||
result = _.forEach(array, (value, index, collection: TResult[]) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
});
|
||||
result = _.forEach(nilArray, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
// Note: ideally we'd like collection TResult[], but it seems the best we can get is List<TResult>.
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult>;
|
||||
|
||||
result = _.forEach<TResult>(list, listIterator);
|
||||
result = _.forEach(list, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult> | null | undefined;
|
||||
|
||||
result = _.forEach<TResult>(nilList, listIterator);
|
||||
result = _.forEach(nilList, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult | null | undefined>;
|
||||
let result: _.Dictionary<TResult>;
|
||||
|
||||
result = _.forEach<TResult>(dictionary, dictionaryIterator);
|
||||
result = _.forEach(dictionary, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType string
|
||||
collection; // $ExpectType Dictionary<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult> | null | undefined;
|
||||
|
||||
result = _.forEach<TResult>(nilDictionary, dictionaryIterator);
|
||||
result = _.forEach(nilDictionary, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType string
|
||||
collection; // $ExpectType Dictionary<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let sample1: TResult = any;
|
||||
sample1 = _.forEach(sample1, objectIterator);
|
||||
|
||||
let sample2: TResult | null | undefined = any;
|
||||
sample2 = _.forEach(sample2, objectIterator);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitWrapper<string>;
|
||||
|
||||
result = _('').forEach(stringIterator);
|
||||
result = _('').forEach((value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitArrayWrapper<TResult>;
|
||||
|
||||
result = _(array).forEach(listIterator);
|
||||
result = _(array).forEach((value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitNillableArrayWrapper<TResult>;
|
||||
|
||||
result = _(nilArray).forEach(listIterator);
|
||||
result = _(nilArray).forEach((value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
@@ -4218,19 +4365,31 @@ namespace TestForEach {
|
||||
{
|
||||
let result: _.LoDashExplicitWrapper<string>;
|
||||
|
||||
result = _('').chain().forEach(stringIterator);
|
||||
result = _('').chain().forEach((value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitArrayWrapper<TResult>;
|
||||
|
||||
result = _(array).chain().forEach(listIterator);
|
||||
result = _(array).chain().forEach((value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitNillableArrayWrapper<TResult>;
|
||||
|
||||
result = _(nilArray).chain().forEach(listIterator);
|
||||
result = _(nilArray).chain().forEach((value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
@@ -4265,65 +4424,99 @@ namespace TestForEachRight {
|
||||
let dictionary: _.Dictionary<TResult> = {};
|
||||
let nilArray: TResult[] | null | undefined = [] as any;
|
||||
let nilList: _.List<TResult> | null | undefined = [] as any;
|
||||
let obj: any = {};
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = obj;
|
||||
let nilDictionary: _.Dictionary<TResult> | null | undefined = any;
|
||||
|
||||
let stringIterator: (char: string, index: number, string: string) => any = (char: string, index: number, string: string) => 1;
|
||||
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => any = (value: TResult, index: number, collection: _.List<TResult>) => 1;
|
||||
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => any = (value: TResult, key: string, collection: _.Dictionary<TResult>) => 1;
|
||||
|
||||
{
|
||||
let result: string;
|
||||
|
||||
result = _.forEachRight('', stringIterator);
|
||||
result = _.forEachRight('', (value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: string | null | undefined;
|
||||
|
||||
result = _.forEachRight('' as (string | null | undefined), stringIterator);
|
||||
result = _.forEachRight('' as (string | null | undefined), (value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: TResult[];
|
||||
|
||||
result = _.forEachRight<TResult>(array, listIterator);
|
||||
result = _.forEachRight(array, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: TResult[] | null | undefined;
|
||||
|
||||
result = _.forEachRight<TResult>(nilArray, listIterator);
|
||||
result = _.forEachRight(nilArray, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult>;
|
||||
|
||||
result = _.forEachRight<TResult>(list, listIterator);
|
||||
result = _.forEachRight(list, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.List<TResult> | null | undefined;
|
||||
|
||||
result = _.forEachRight<TResult>(nilList, listIterator);
|
||||
result = _.forEachRight(nilList, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult | null | undefined>;
|
||||
let result: _.Dictionary<TResult>;
|
||||
|
||||
result = _.forEachRight<TResult>(dictionary, dictionaryIterator);
|
||||
result = _.forEachRight(dictionary, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType string
|
||||
collection; // $ExpectType Dictionary<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<TResult> | null | undefined;
|
||||
|
||||
result = _.forEachRight<TResult>(nilDictionary, dictionaryIterator);
|
||||
result = _.forEachRight(nilDictionary, (value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType string
|
||||
collection; // $ExpectType Dictionary<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitWrapper<string>;
|
||||
|
||||
result = _('').forEachRight(stringIterator);
|
||||
result = _('').forEachRight((value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
@@ -4365,25 +4558,37 @@ namespace TestForEachRight {
|
||||
{
|
||||
let result: _.LoDashExplicitWrapper<string>;
|
||||
|
||||
result = _('').chain().forEachRight(stringIterator);
|
||||
result = _('').chain().forEachRight((value, index, collection) => {
|
||||
value; // $ExpectType string
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType string
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitArrayWrapper<TResult>;
|
||||
|
||||
result = _(array).chain().forEachRight(listIterator);
|
||||
result = _(array).chain().forEachRight((value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitNillableArrayWrapper<TResult>;
|
||||
|
||||
result = _(nilArray).chain().forEachRight(listIterator);
|
||||
result = _(nilArray).chain().forEachRight((value, index, collection) => {
|
||||
value; // $ExpectType TResult
|
||||
index; // $ExpectType number
|
||||
collection; // $ExpectType ArrayLike<TResult>
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitObjectWrapper<_.List<TResult>>;
|
||||
|
||||
result = _(list).chain().forEachRight<TResult>(listIterator);
|
||||
result = _(list).chain().forEachRight(listIterator);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -6912,7 +7117,7 @@ namespace TestIsArray {
|
||||
let value: number|string[]|boolean[] = any;
|
||||
|
||||
if (_.isArray(value)) {
|
||||
value; // $ExpectType boolean[] | string[]
|
||||
value; // $ExpectType string[] | boolean[]
|
||||
}
|
||||
else {
|
||||
value; // $ExpectType number
|
||||
@@ -8277,11 +8482,24 @@ namespace TestMean {
|
||||
|
||||
let result: number;
|
||||
|
||||
result = _.mean(array);
|
||||
result = _.mean<number>(array);
|
||||
|
||||
result = _(array).mean();
|
||||
}
|
||||
|
||||
// _.meanBy
|
||||
namespace TestMean {
|
||||
let array: TResult[] = [];
|
||||
|
||||
let result: number;
|
||||
|
||||
result = _.meanBy(array, (x) => x.a);
|
||||
result = _.meanBy(array, 'a');
|
||||
|
||||
result = _(array).mean();
|
||||
}
|
||||
|
||||
// _.min
|
||||
namespace TestMin {
|
||||
let array: number[] = [];
|
||||
@@ -9457,6 +9675,8 @@ namespace TestFindKey {
|
||||
|
||||
result = _.findKey<{a: number;}, {a: string;}>({a: ''}, {a: 42});
|
||||
|
||||
result = _.findKey({a: { b: 5 }}, ['b', 5]);
|
||||
|
||||
result = _<{a: string;}>({a: ''}).findKey();
|
||||
|
||||
result = _<{a: string;}>({a: ''}).findKey(predicateFn);
|
||||
@@ -9510,6 +9730,8 @@ namespace TestFindLastKey {
|
||||
|
||||
result = _.findLastKey<{a: number;}, {a: string;}>({a: ''}, {a: 42});
|
||||
|
||||
result = _.findLastKey({a: { b: 5 }}, ['b', 5]);
|
||||
|
||||
result = _<{a: string;}>({a: ''}).findLastKey();
|
||||
|
||||
result = _<{a: string;}>({a: ''}).findLastKey(predicateFn);
|
||||
@@ -11970,9 +12192,9 @@ namespace TestIdentity {
|
||||
// _.iteratee
|
||||
namespace TestIteratee {
|
||||
{
|
||||
let result: (...args: any[]) => TResult;
|
||||
|
||||
result = _.iteratee<TResult>(Function);
|
||||
_.iteratee((...args: any[]): TResult => any); // $ExpectType (...args: any[]) => TResult
|
||||
_.iteratee((a: TResult): boolean => any); // $ExpectType (a: TResult) => boolean
|
||||
_.iteratee((a: TResult | undefined): a is undefined => any); // $ExpectType (a: TResult | undefined) => a is undefined
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user