mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Lowdb test fix (#25204)
* lodash: _.get should with numeric keys, too. Also added some better tests. * lodash: add one more NumericDictionary overload for _.get * lodash: more reasonable index for _.get tests * lodash: object type should not be here (fixes #23293) * lodash: reduce should always return T if no accumulator (#14758) * lodash: fix iterator types, remove thisArg from documentation * lodash: return more specific type for stubTrue and stubFalse * lowdb: fix failing tests
This commit is contained in:
committed by
Wesley Wigham
parent
3d6c3d223b
commit
64104e9760
Vendored
+15
-134
@@ -577,20 +577,10 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a slice of array excluding elements dropped from the end. Elements are dropped until predicate
|
||||
* returns falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* match the properties of the given object, else false.
|
||||
* returns falsey. The predicate is invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* @param array The array to query.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the slice of array.
|
||||
*/
|
||||
dropRightWhile<T>(
|
||||
@@ -624,20 +614,10 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a slice of array excluding elements dropped from the beginning. Elements are dropped until predicate
|
||||
* returns falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* returns falsey. The predicate is invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* @param array The array to query.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the slice of array.
|
||||
*/
|
||||
dropWhile<T>(
|
||||
@@ -797,15 +777,6 @@ declare module "../index" {
|
||||
* This method is like _.find except that it returns the index of the first element predicate returns truthy
|
||||
* for instead of the element itself.
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
*
|
||||
* @param array The array to search.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param fromIndex The index to search from.
|
||||
@@ -846,15 +817,6 @@ declare module "../index" {
|
||||
/**
|
||||
* This method is like _.findIndex except that it iterates over elements of collection from right to left.
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
*
|
||||
* @param array The array to search.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param fromIndex The index to search from.
|
||||
@@ -1881,22 +1843,12 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Removes all elements from array that predicate returns truthy for and returns an array of the removed
|
||||
* elements. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* elements. The predicate is invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* Note: Unlike _.filter, this method mutates array.
|
||||
*
|
||||
* @param array The array to modify.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the new array of removed elements.
|
||||
*/
|
||||
remove<T>(
|
||||
@@ -2359,53 +2311,29 @@ declare module "../index" {
|
||||
* _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
|
||||
* // => [1.1, 2.2]
|
||||
*/
|
||||
sortedUniqBy(
|
||||
array: string | null | undefined,
|
||||
iteratee: StringIterator<NotVoid>
|
||||
): string[];
|
||||
|
||||
/**
|
||||
* @see _.sortedUniqBy
|
||||
*/
|
||||
sortedUniqBy<T>(
|
||||
array: List<T> | null | undefined,
|
||||
iteratee: ListIteratee<T>
|
||||
iteratee: ValueIteratee<T>
|
||||
): T[];
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.sortedUniqBy
|
||||
*/
|
||||
sortedUniqBy(
|
||||
this: LoDashImplicitWrapper<string | null | undefined>,
|
||||
iteratee: StringIterator<NotVoid>
|
||||
): LoDashImplicitWrapper<string[]>;
|
||||
|
||||
/**
|
||||
* @see _.sortedUniqBy
|
||||
*/
|
||||
sortedUniqBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee: ListIteratee<T>
|
||||
iteratee: ValueIteratee<T>
|
||||
): LoDashImplicitWrapper<T[]>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.sortedUniqBy
|
||||
*/
|
||||
sortedUniqBy(
|
||||
this: LoDashExplicitWrapper<string | null | undefined>,
|
||||
iteratee: StringIterator<NotVoid>
|
||||
): LoDashExplicitWrapper<string[]>;
|
||||
|
||||
/**
|
||||
* @see _.sortedUniqBy
|
||||
*/
|
||||
sortedUniqBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee: ListIteratee<T>
|
||||
iteratee: ValueIteratee<T>
|
||||
): LoDashExplicitWrapper<T[]>;
|
||||
}
|
||||
|
||||
@@ -2512,20 +2440,10 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a slice of array with elements taken from the end. Elements are taken until predicate returns
|
||||
* falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* falsey. The predicate is invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* @param array The array to query.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the slice of array.
|
||||
*/
|
||||
takeRightWhile<T>(
|
||||
@@ -2559,20 +2477,10 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns
|
||||
* falsey. The predicate is bound to thisArg and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* falsey. The predicate is invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* @param array The array to query.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the slice of array.
|
||||
*/
|
||||
takeWhile<T>(
|
||||
@@ -2958,53 +2866,29 @@ declare module "../index" {
|
||||
* _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
||||
* // => [{ 'x': 1 }, { 'x': 2 }]
|
||||
*/
|
||||
uniqBy(
|
||||
array: string | null | undefined,
|
||||
iteratee: StringIterator<NotVoid>
|
||||
): string[];
|
||||
|
||||
/**
|
||||
* @see _.uniqBy
|
||||
*/
|
||||
uniqBy<T>(
|
||||
array: List<T> | null | undefined,
|
||||
iteratee: ListIteratee<T>
|
||||
iteratee: ValueIteratee<T>
|
||||
): T[];
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.uniqBy
|
||||
*/
|
||||
uniqBy(
|
||||
this: LoDashImplicitWrapper<string | null | undefined>,
|
||||
iteratee: StringIterator<NotVoid>
|
||||
): LoDashImplicitWrapper<string[]>;
|
||||
|
||||
/**
|
||||
* @see _.uniqBy
|
||||
*/
|
||||
uniqBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee: ListIteratee<T>
|
||||
iteratee: ValueIteratee<T>
|
||||
): LoDashImplicitWrapper<T[]>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.uniqBy
|
||||
*/
|
||||
uniqBy(
|
||||
this: LoDashExplicitWrapper<string | null | undefined>,
|
||||
iteratee: StringIterator<NotVoid>
|
||||
): LoDashExplicitWrapper<string[]>;
|
||||
|
||||
/**
|
||||
* @see _.uniqBy
|
||||
*/
|
||||
uniqBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee: ListIteratee<T>
|
||||
iteratee: ValueIteratee<T>
|
||||
): LoDashExplicitWrapper<T[]>;
|
||||
}
|
||||
|
||||
@@ -3085,12 +2969,10 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* This method is like _.unzip except that it accepts an iteratee to specify how regrouped values should be
|
||||
* combined. The iteratee is bound to thisArg and invoked with four arguments: (accumulator, value, index,
|
||||
* group).
|
||||
* combined. The iteratee is invoked with four arguments: (accumulator, value, index, group).
|
||||
*
|
||||
* @param array The array of grouped elements to process.
|
||||
* @param iteratee The function to combine regrouped values.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the new array of regrouped elements.
|
||||
*/
|
||||
unzipWith<T, TResult>(
|
||||
@@ -3643,11 +3525,10 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* This method is like _.zip except that it accepts an iteratee to specify how grouped values should be
|
||||
* combined. The iteratee is bound to thisArg and invoked with four arguments: (accumulator, value, index,
|
||||
* combined. The iteratee is invoked with four arguments: (accumulator, value, index,
|
||||
* group).
|
||||
* @param [arrays] The arrays to process.
|
||||
* @param [iteratee] The function to combine grouped values.
|
||||
* @param [thisArg] The `this` binding of `iteratee`.
|
||||
* @param arrays The arrays to process.
|
||||
* @param iteratee The function to combine grouped values.
|
||||
* @return Returns the new array of grouped elements.
|
||||
*/
|
||||
zipWith<T, TResult>(
|
||||
|
||||
Vendored
+82
-230
@@ -6,34 +6,15 @@ declare module "../index" {
|
||||
/**
|
||||
* Creates an object composed of keys generated from the results of running each element of collection through
|
||||
* iteratee. The corresponding value of each key is the number of times the key was returned by iteratee. The
|
||||
* iteratee is bound to thisArg and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for iteratee the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for iteratee the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* iteratee is invoked with one argument: (value).
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the composed aggregate object.
|
||||
*/
|
||||
countBy<T>(
|
||||
collection: string | null | undefined,
|
||||
iteratee?: StringIterator<T>
|
||||
): Dictionary<number>;
|
||||
|
||||
/**
|
||||
* @see _.countBy
|
||||
*/
|
||||
countBy<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): Dictionary<number>;
|
||||
|
||||
/**
|
||||
@@ -41,25 +22,17 @@ declare module "../index" {
|
||||
*/
|
||||
countBy<T extends object>(
|
||||
collection: T | null | undefined,
|
||||
iteratee?: ObjectIteratee<T>
|
||||
iteratee?: ValueIteratee<T[keyof T]>
|
||||
): Dictionary<number>;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.countBy
|
||||
*/
|
||||
countBy<T>(
|
||||
this: LoDashImplicitWrapper<string | null | undefined>,
|
||||
iteratee?: StringIterator<T>
|
||||
): LoDashImplicitWrapper<Dictionary<number>>;
|
||||
|
||||
/**
|
||||
* @see _.countBy
|
||||
*/
|
||||
countBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): LoDashImplicitWrapper<Dictionary<number>>;
|
||||
|
||||
/**
|
||||
@@ -67,25 +40,17 @@ declare module "../index" {
|
||||
*/
|
||||
countBy<T extends object>(
|
||||
this: LoDashImplicitWrapper<T | null | undefined>,
|
||||
iteratee?: ObjectIteratee<T>
|
||||
iteratee?: ValueIteratee<T[keyof T]>
|
||||
): LoDashImplicitWrapper<Dictionary<number>>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.countBy
|
||||
*/
|
||||
countBy<T>(
|
||||
this: LoDashExplicitWrapper<string | null | undefined>,
|
||||
iteratee?: StringIterator<T>
|
||||
): LoDashExplicitWrapper<Dictionary<number>>;
|
||||
|
||||
/**
|
||||
* @see _.countBy
|
||||
*/
|
||||
countBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): LoDashExplicitWrapper<Dictionary<number>>;
|
||||
|
||||
/**
|
||||
@@ -93,7 +58,7 @@ declare module "../index" {
|
||||
*/
|
||||
countBy<T extends object>(
|
||||
this: LoDashExplicitWrapper<T | null | undefined>,
|
||||
iteratee?: ObjectIteratee<T>
|
||||
iteratee?: ValueIteratee<T[keyof T]>
|
||||
): LoDashExplicitWrapper<Dictionary<number>>;
|
||||
}
|
||||
|
||||
@@ -243,20 +208,10 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The
|
||||
* predicate is bound to thisArg and invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* predicate is invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the new filtered array.
|
||||
*/
|
||||
filter(
|
||||
@@ -386,16 +341,7 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Iterates over elements of collection, returning the first element predicate returns truthy for.
|
||||
* The predicate is bound to thisArg and invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* The predicate is invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* @param collection The collection to search.
|
||||
* @param predicate The function invoked per iteration.
|
||||
@@ -1070,8 +1016,7 @@ declare module "../index" {
|
||||
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Iterates over elements of collection invoking iteratee for each element. The iteratee is bound to thisArg
|
||||
* and invoked with three arguments:
|
||||
* Iterates over elements of collection invoking iteratee for each element. The iteratee is invoked with three arguments:
|
||||
* (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.
|
||||
*
|
||||
* Note: As with other "Collections" methods, objects with a "length" property are iterated like arrays. To
|
||||
@@ -1081,7 +1026,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
*/
|
||||
forEach<T>(
|
||||
collection: T[],
|
||||
@@ -1189,7 +1133,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param iteratee The function called per iteration.
|
||||
* @param thisArg The this binding of callback.
|
||||
*/
|
||||
forEachRight<T>(
|
||||
collection: T[],
|
||||
@@ -1293,34 +1236,15 @@ declare module "../index" {
|
||||
/**
|
||||
* Creates an object composed of keys generated from the results of running each element of collection through
|
||||
* iteratee. The corresponding value of each key is an array of the elements responsible for generating the
|
||||
* key. The iteratee is bound to thisArg and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for iteratee the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for iteratee the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* key. The iteratee is invoked with one argument: (value).
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the composed aggregate object.
|
||||
*/
|
||||
groupBy(
|
||||
collection: string | null | undefined,
|
||||
iteratee?: StringIterator<NotVoid>
|
||||
): Dictionary<string[]>;
|
||||
|
||||
/**
|
||||
* @see _.groupBy
|
||||
*/
|
||||
groupBy<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): Dictionary<T[]>;
|
||||
|
||||
/**
|
||||
@@ -1328,25 +1252,17 @@ declare module "../index" {
|
||||
*/
|
||||
groupBy<T extends object>(
|
||||
collection: T | null | undefined,
|
||||
iteratee?: ObjectIteratee<T>
|
||||
iteratee?: ValueIteratee<T[keyof T]>
|
||||
): Dictionary<Array<T[keyof T]>>;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.groupBy
|
||||
*/
|
||||
groupBy(
|
||||
this: LoDashImplicitWrapper<string | null | undefined>,
|
||||
iteratee?: StringIterator<NotVoid>
|
||||
): LoDashImplicitWrapper<Dictionary<string[]>>;
|
||||
|
||||
/**
|
||||
* @see _.groupBy
|
||||
*/
|
||||
groupBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): LoDashImplicitWrapper<Dictionary<T[]>>;
|
||||
|
||||
/**
|
||||
@@ -1354,25 +1270,17 @@ declare module "../index" {
|
||||
*/
|
||||
groupBy<T extends object>(
|
||||
this: LoDashImplicitWrapper<T | null | undefined>,
|
||||
iteratee?: ObjectIteratee<T>
|
||||
iteratee?: ValueIteratee<T[keyof T]>
|
||||
): LoDashImplicitWrapper<Dictionary<Array<T[keyof T]>>>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.groupBy
|
||||
*/
|
||||
groupBy(
|
||||
this: LoDashExplicitWrapper<string | null | undefined>,
|
||||
iteratee?: StringIterator<NotVoid>
|
||||
): LoDashExplicitWrapper<Dictionary<string[]>>;
|
||||
|
||||
/**
|
||||
* @see _.groupBy
|
||||
*/
|
||||
groupBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): LoDashExplicitWrapper<Dictionary<T[]>>;
|
||||
|
||||
/**
|
||||
@@ -1380,7 +1288,7 @@ declare module "../index" {
|
||||
*/
|
||||
groupBy<T extends object>(
|
||||
this: LoDashExplicitWrapper<T | null | undefined>,
|
||||
iteratee?: ObjectIteratee<T>
|
||||
iteratee?: ValueIteratee<T[keyof T]>
|
||||
): LoDashExplicitWrapper<Dictionary<Array<T[keyof T]>>>;
|
||||
}
|
||||
|
||||
@@ -1489,34 +1397,15 @@ declare module "../index" {
|
||||
/**
|
||||
* Creates an object composed of keys generated from the results of running each element of collection through
|
||||
* iteratee. The corresponding value of each key is the last element responsible for generating the key. The
|
||||
* iteratee function is bound to thisArg and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for iteratee the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for iteratee the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* iteratee function is invoked with one argument: (value).
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the composed aggregate object.
|
||||
*/
|
||||
keyBy(
|
||||
collection: string | null | undefined,
|
||||
iteratee?: StringIterator<PropertyName>
|
||||
): Dictionary<string>;
|
||||
|
||||
/**
|
||||
* @see _.keyBy
|
||||
*/
|
||||
keyBy<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
iteratee?: ListIterateeCustom<T, PropertyName>
|
||||
iteratee?: ValueIterateeCustom<T, PropertyName>
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
@@ -1524,25 +1413,17 @@ declare module "../index" {
|
||||
*/
|
||||
keyBy<T extends object>(
|
||||
collection: T | null | undefined,
|
||||
iteratee?: ObjectIterateeCustom<T, PropertyName>
|
||||
iteratee?: ValueIterateeCustom<T[keyof T], PropertyName>
|
||||
): Dictionary<T[keyof T]>;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.keyBy
|
||||
*/
|
||||
keyBy(
|
||||
this: LoDashImplicitWrapper<string | null | undefined>,
|
||||
iteratee?: StringIterator<PropertyName>
|
||||
): LoDashImplicitWrapper<Dictionary<string>>;
|
||||
|
||||
/**
|
||||
* @see _.keyBy
|
||||
*/
|
||||
keyBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIterateeCustom<T, PropertyName>
|
||||
iteratee?: ValueIterateeCustom<T, PropertyName>
|
||||
): LoDashImplicitWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
@@ -1550,25 +1431,17 @@ declare module "../index" {
|
||||
*/
|
||||
keyBy<T extends object>(
|
||||
this: LoDashImplicitWrapper<T | null | undefined>,
|
||||
iteratee?: ObjectIterateeCustom<T, PropertyName>
|
||||
iteratee?: ValueIterateeCustom<T[keyof T], PropertyName>
|
||||
): LoDashImplicitWrapper<Dictionary<T[keyof T]>>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.keyBy
|
||||
*/
|
||||
keyBy(
|
||||
this: LoDashExplicitWrapper<string | null | undefined>,
|
||||
iteratee?: StringIterator<PropertyName>
|
||||
): LoDashExplicitWrapper<Dictionary<string>>;
|
||||
|
||||
/**
|
||||
* @see _.keyBy
|
||||
*/
|
||||
keyBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIterateeCustom<T, PropertyName>
|
||||
iteratee?: ValueIterateeCustom<T, PropertyName>
|
||||
): LoDashExplicitWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
@@ -1576,7 +1449,7 @@ declare module "../index" {
|
||||
*/
|
||||
keyBy<T extends object>(
|
||||
this: LoDashExplicitWrapper<T | null | undefined>,
|
||||
iteratee?: ObjectIterateeCustom<T, PropertyName>
|
||||
iteratee?: ValueIterateeCustom<T[keyof T], PropertyName>
|
||||
): LoDashExplicitWrapper<Dictionary<T[keyof T]>>;
|
||||
}
|
||||
|
||||
@@ -1584,17 +1457,8 @@ declare module "../index" {
|
||||
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates an array of values by running each element in collection through iteratee. The iteratee is bound to
|
||||
* thisArg and invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for iteratee the created _.property style callback returns the property value
|
||||
* of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for iteratee the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
* Creates an array of values by running each element in collection through iteratee. The iteratee is
|
||||
* invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues,
|
||||
* _.reject, and _.some.
|
||||
@@ -1606,7 +1470,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the new mapped array.
|
||||
*/
|
||||
map<T, TResult>(
|
||||
@@ -1908,20 +1771,10 @@ declare module "../index" {
|
||||
/**
|
||||
* Creates an array of elements split into two groups, the first of which contains elements predicate returns truthy for,
|
||||
* while the second of which contains elements predicate returns falsey for.
|
||||
* The predicate is bound to thisArg and invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback
|
||||
* returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback
|
||||
* returns true for elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns
|
||||
* true for elements that have the properties of the given object, else false.
|
||||
* The predicate is invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param callback The function called per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the array of grouped elements.
|
||||
**/
|
||||
partition<T>(
|
||||
@@ -1982,7 +1835,7 @@ declare module "../index" {
|
||||
* element in the collection through the callback, where each successive callback execution
|
||||
* consumes the return value of the previous execution. If accumulator is not provided the
|
||||
* first element of the collection will be used as the initial accumulator value. The callback
|
||||
* is bound to thisArg and invoked with four arguments; (accumulator, value, index|key, collection).
|
||||
* is invoked with four arguments: (accumulator, value, index|key, collection).
|
||||
* @param collection The collection to iterate over.
|
||||
* @param callback The function called per iteration.
|
||||
* @param accumulator Initial value of the accumulator.
|
||||
@@ -2015,26 +1868,26 @@ declare module "../index" {
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T, TResult>(
|
||||
reduce<T>(
|
||||
collection: T[] | null | undefined,
|
||||
callback: MemoListIterator<T, TResult, T[]>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, T[]>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T, TResult>(
|
||||
reduce<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
callback: MemoListIterator<T, TResult, List<T>>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, List<T>>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T extends object, TResult>(
|
||||
reduce<T extends object>(
|
||||
collection: T | null | undefined,
|
||||
callback: MemoObjectIterator<T[keyof T], TResult, T>
|
||||
): TResult | undefined;
|
||||
callback: MemoObjectIterator<T[keyof T], T[keyof T], T>
|
||||
): T[keyof T] | undefined;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
@@ -2068,26 +1921,26 @@ declare module "../index" {
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T, TResult>(
|
||||
reduce<T>(
|
||||
this: LoDashImplicitWrapper<T[] | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, T[]>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, T[]>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T, TResult>(
|
||||
reduce<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, List<T>>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, List<T>>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T extends object, TResult>(
|
||||
reduce<T extends object>(
|
||||
this: LoDashImplicitWrapper<T | null | undefined>,
|
||||
callback: MemoObjectIterator<T[keyof T], TResult, T>
|
||||
): TResult | undefined;
|
||||
callback: MemoObjectIterator<T[keyof T], T[keyof T], T>
|
||||
): T[keyof T] | undefined;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
@@ -2121,26 +1974,26 @@ declare module "../index" {
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T, TResult>(
|
||||
reduce<T>(
|
||||
this: LoDashExplicitWrapper<T[] | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, T[]>
|
||||
): LoDashExplicitWrapper<TResult | undefined>;
|
||||
callback: MemoListIterator<T, T, T[]>
|
||||
): LoDashExplicitWrapper<T | undefined>;
|
||||
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T, TResult>(
|
||||
reduce<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, List<T>>
|
||||
): LoDashExplicitWrapper<TResult | undefined>;
|
||||
callback: MemoListIterator<T, T, List<T>>
|
||||
): LoDashExplicitWrapper<T | undefined>;
|
||||
|
||||
/**
|
||||
* @see _.reduce
|
||||
**/
|
||||
reduce<T extends object, TResult>(
|
||||
reduce<T extends object>(
|
||||
this: LoDashExplicitWrapper<T | null | undefined>,
|
||||
callback: MemoObjectIterator<T[keyof T], TResult, T>
|
||||
): LoDashExplicitWrapper<TResult | undefined>;
|
||||
callback: MemoObjectIterator<T[keyof T], T[keyof T], T>
|
||||
): LoDashExplicitWrapper<T[keyof T] | undefined>;
|
||||
}
|
||||
|
||||
// reduceRight
|
||||
@@ -2181,26 +2034,26 @@ declare module "../index" {
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T, TResult>(
|
||||
reduceRight<T>(
|
||||
collection: T[] | null | undefined,
|
||||
callback: MemoListIterator<T, TResult, T[]>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, T[]>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T, TResult>(
|
||||
reduceRight<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
callback: MemoListIterator<T, TResult, List<T>>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, List<T>>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T extends object, TResult>(
|
||||
reduceRight<T extends object>(
|
||||
collection: T | null | undefined,
|
||||
callback: MemoObjectIterator<T[keyof T], TResult, T>
|
||||
): TResult | undefined;
|
||||
callback: MemoObjectIterator<T[keyof T], T[keyof T], T>
|
||||
): T[keyof T] | undefined;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
@@ -2234,26 +2087,26 @@ declare module "../index" {
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T, TResult>(
|
||||
reduceRight<T>(
|
||||
this: LoDashImplicitWrapper<T[] | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, T[]>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, T[]>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T, TResult>(
|
||||
reduceRight<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, List<T>>
|
||||
): TResult | undefined;
|
||||
callback: MemoListIterator<T, T, List<T>>
|
||||
): T | undefined;
|
||||
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T extends object, TResult>(
|
||||
reduceRight<T extends object>(
|
||||
this: LoDashImplicitWrapper<T | null | undefined>,
|
||||
callback: MemoObjectIterator<T[keyof T], TResult, T>
|
||||
): TResult | undefined;
|
||||
callback: MemoObjectIterator<T[keyof T], T[keyof T], T>
|
||||
): T[keyof T] | undefined;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
@@ -2287,26 +2140,26 @@ declare module "../index" {
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T, TResult>(
|
||||
reduceRight<T>(
|
||||
this: LoDashExplicitWrapper<T[] | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, T[]>
|
||||
): LoDashExplicitWrapper<TResult | undefined>;
|
||||
callback: MemoListIterator<T, T, T[]>
|
||||
): LoDashExplicitWrapper<T | undefined>;
|
||||
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T, TResult>(
|
||||
reduceRight<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
callback: MemoListIterator<T, TResult, List<T>>
|
||||
): LoDashExplicitWrapper<TResult | undefined>;
|
||||
callback: MemoListIterator<T, T, List<T>>
|
||||
): LoDashExplicitWrapper<T | undefined>;
|
||||
|
||||
/**
|
||||
* @see _.reduceRight
|
||||
**/
|
||||
reduceRight<T extends object, TResult>(
|
||||
reduceRight<T extends object>(
|
||||
this: LoDashExplicitWrapper<T | null | undefined>,
|
||||
callback: MemoObjectIterator<T[keyof T], TResult, T>
|
||||
): LoDashExplicitWrapper<TResult | undefined>;
|
||||
callback: MemoObjectIterator<T[keyof T], T[keyof T], T>
|
||||
): LoDashExplicitWrapper<T[keyof T] | undefined>;
|
||||
}
|
||||
|
||||
// reject
|
||||
@@ -2318,7 +2171,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the new filtered array.
|
||||
*/
|
||||
reject(
|
||||
|
||||
Vendored
+1
-1
@@ -182,7 +182,7 @@ declare module "../index" {
|
||||
type ArrayIterator<T, TResult> = (value: T, index: number, collection: T[]) => TResult;
|
||||
type ListIterator<T, TResult> = (value: T, index: number, collection: List<T>) => TResult;
|
||||
type ListIteratee<T> = ListIterator<T, NotVoid> | string | [string, any] | PartialDeep<T>;
|
||||
type ListIterateeCustom<T, TResult> = ListIterator<T, TResult> | string | object | [string, any] | PartialDeep<T>;
|
||||
type ListIterateeCustom<T, TResult> = ListIterator<T, TResult> | string | [string, any] | PartialDeep<T>;
|
||||
type ListIteratorTypeGuard<T, S extends T> = (value: T, index: number, collection: List<T>) => value is S;
|
||||
|
||||
// Note: key should be string, not keyof T, because the actual object may contain extra properties that were not specified in the type.
|
||||
|
||||
Vendored
+12
-12
@@ -160,7 +160,7 @@ declare module "../index" {
|
||||
*
|
||||
* @category Math
|
||||
* @param array The array to iterate over.
|
||||
* @param [iteratee=_.identity] The iteratee invoked per element.
|
||||
* @param iteratee The iteratee invoked per element.
|
||||
* @returns Returns the maximum value.
|
||||
* @example
|
||||
*
|
||||
@@ -175,7 +175,7 @@ declare module "../index" {
|
||||
*/
|
||||
maxBy<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): T | undefined;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ declare module "../index" {
|
||||
*/
|
||||
maxBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): T | undefined;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ declare module "../index" {
|
||||
*/
|
||||
maxBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): LoDashExplicitWrapper<T | undefined>;
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ declare module "../index" {
|
||||
*
|
||||
* @category Math
|
||||
* @param array The array to iterate over.
|
||||
* @param [iteratee=_.identity] The iteratee invoked per element.
|
||||
* @param iteratee The iteratee invoked per element.
|
||||
* @returns Returns the mean.
|
||||
* @example
|
||||
*
|
||||
@@ -249,7 +249,7 @@ declare module "../index" {
|
||||
*/
|
||||
meanBy<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): number;
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ declare module "../index" {
|
||||
*/
|
||||
meanBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): number;
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ declare module "../index" {
|
||||
*/
|
||||
meanBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): LoDashExplicitWrapper<number>;
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ declare module "../index" {
|
||||
*
|
||||
* @category Math
|
||||
* @param array The array to iterate over.
|
||||
* @param [iteratee=_.identity] The iteratee invoked per element.
|
||||
* @param iteratee The iteratee invoked per element.
|
||||
* @returns Returns the minimum value.
|
||||
* @example
|
||||
*
|
||||
@@ -328,7 +328,7 @@ declare module "../index" {
|
||||
*/
|
||||
minBy<T>(
|
||||
collection: List<T> | null | undefined,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): T | undefined;
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ declare module "../index" {
|
||||
*/
|
||||
minBy<T>(
|
||||
this: LoDashImplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): T | undefined;
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ declare module "../index" {
|
||||
*/
|
||||
minBy<T>(
|
||||
this: LoDashExplicitWrapper<List<T> | null | undefined>,
|
||||
iteratee?: ListIteratee<T>
|
||||
iteratee?: ValueIteratee<T>
|
||||
): LoDashExplicitWrapper<T | undefined>;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+6
-42
@@ -1370,18 +1370,8 @@ declare module "../index" {
|
||||
* This method is like _.find except that it returns the key of the first element predicate returns truthy for
|
||||
* instead of the element itself.
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
*
|
||||
* @param object The object to search.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the key of the matched element, else undefined.
|
||||
*/
|
||||
findKey<T>(
|
||||
@@ -1416,18 +1406,8 @@ declare module "../index" {
|
||||
/**
|
||||
* This method is like _.findKey except that it iterates over elements of a collection in the opposite order.
|
||||
*
|
||||
* If a property name is provided for predicate the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for predicate the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
*
|
||||
* @param object The object to search.
|
||||
* @param predicate The function invoked per iteration.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return Returns the key of the matched element, else undefined.
|
||||
*/
|
||||
findLastKey<T>(
|
||||
@@ -1461,12 +1441,11 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Iterates over own and inherited enumerable properties of an object invoking iteratee for each property. The
|
||||
* iteratee is bound to thisArg and invoked with three arguments: (value, key, object). Iteratee functions may
|
||||
* iteratee is invoked with three arguments: (value, key, object). Iteratee functions may
|
||||
* exit iteration early by explicitly returning false.
|
||||
*
|
||||
* @param object The object to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns object.
|
||||
*/
|
||||
forIn<T>(
|
||||
@@ -1501,7 +1480,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param object The object to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns object.
|
||||
*/
|
||||
forInRight<T>(
|
||||
@@ -1533,12 +1511,11 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Iterates over own enumerable properties of an object invoking iteratee for each property. The iteratee is
|
||||
* bound to thisArg and invoked with three arguments: (value, key, object). Iteratee functions may exit
|
||||
* invoked with three arguments: (value, key, object). Iteratee functions may exit
|
||||
* iteration early by explicitly returning false.
|
||||
*
|
||||
* @param object The object to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns object.
|
||||
*/
|
||||
forOwn<T>(
|
||||
@@ -1573,7 +1550,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param object The object to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns object.
|
||||
*/
|
||||
forOwnRight<T>(
|
||||
@@ -2199,7 +2175,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param object The object to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the new mapped object.
|
||||
*/
|
||||
mapKeys<T>(
|
||||
@@ -2257,21 +2232,11 @@ declare module "../index" {
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates an object with the same keys as object and values generated by running each own
|
||||
* enumerable property of object through iteratee. The iteratee function is bound to thisArg
|
||||
* and invoked with three arguments: (value, key, object).
|
||||
*
|
||||
* If a property name is provided iteratee the created "_.property" style callback returns
|
||||
* the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the creted "_.matchesProperty" style callback returns
|
||||
* true for elements that have a matching property value, else false;.
|
||||
*
|
||||
* If an object is provided for iteratee the created "_.matches" style callback returns true
|
||||
* for elements that have the properties of the given object, else false.
|
||||
* enumerable property of object through iteratee. The iteratee function is
|
||||
* invoked with three arguments: (value, key, object).
|
||||
*
|
||||
* @param object The object to iterate over.
|
||||
* @param [iteratee=_.identity] The function invoked per iteration.
|
||||
* @param [thisArg] The `this` binding of `iteratee`.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @return Returns the new mapped object.
|
||||
*/
|
||||
mapValues<TResult>(obj: string | null | undefined, callback: StringIterator<TResult>): NumericDictionary<TResult>;
|
||||
@@ -3363,13 +3328,12 @@ declare module "../index" {
|
||||
/**
|
||||
* An alternative to _.reduce; this method transforms object to a new accumulator object which is the result of
|
||||
* running each of its own enumerable properties through iteratee, with each invocation potentially mutating
|
||||
* the accumulator object. The iteratee is bound to thisArg and invoked with four arguments: (accumulator,
|
||||
* the accumulator object. The iteratee is invoked with four arguments: (accumulator,
|
||||
* value, key, object). Iteratee functions may exit iteration early by explicitly returning false.
|
||||
*
|
||||
* @param object The object to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param accumulator The custom accumulator value.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the accumulated value.
|
||||
*/
|
||||
transform<T, TResult>(
|
||||
|
||||
Vendored
+1
-3
@@ -141,13 +141,12 @@ declare module "../index" {
|
||||
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* This method invokes interceptor and returns value. The interceptor is bound to thisArg and invoked with one
|
||||
* This method invokes interceptor and returns value. The interceptor is invoked with one
|
||||
* argument; (value). The purpose of this method is to "tap into" a method chain in order to perform operations
|
||||
* on intermediate results within the chain.
|
||||
*
|
||||
* @param value The value to provide to interceptor.
|
||||
* @param interceptor The function to invoke.
|
||||
* @parem thisArg The this binding of interceptor.
|
||||
* @return Returns value.
|
||||
**/
|
||||
tap<T>(
|
||||
@@ -173,7 +172,6 @@ declare module "../index" {
|
||||
*
|
||||
* @param value The value to provide to interceptor.
|
||||
* @param interceptor The function to invoke.
|
||||
* @param thisArg The this binding of interceptor.
|
||||
* @return Returns the result of interceptor.
|
||||
*/
|
||||
thru<T, TResult>(
|
||||
|
||||
Vendored
+6
-6
@@ -1250,21 +1250,21 @@ declare module "../index" {
|
||||
*
|
||||
* @returns Returns `false`.
|
||||
*/
|
||||
stubFalse(): boolean;
|
||||
stubFalse(): false;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.stubFalse
|
||||
*/
|
||||
stubFalse(): boolean;
|
||||
stubFalse(): false;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.stubFalse
|
||||
*/
|
||||
stubFalse(): LoDashExplicitWrapper<boolean>;
|
||||
stubFalse(): LoDashExplicitWrapper<false>;
|
||||
}
|
||||
|
||||
// stubObject
|
||||
@@ -1325,21 +1325,21 @@ declare module "../index" {
|
||||
*
|
||||
* @returns Returns `true`.
|
||||
*/
|
||||
stubTrue(): boolean;
|
||||
stubTrue(): true;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.stubTrue
|
||||
*/
|
||||
stubTrue(): boolean;
|
||||
stubTrue(): true;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.stubTrue
|
||||
*/
|
||||
stubTrue(): LoDashExplicitWrapper<boolean>;
|
||||
stubTrue(): LoDashExplicitWrapper<true>;
|
||||
}
|
||||
|
||||
// times
|
||||
|
||||
Vendored
+28
-53
@@ -350,20 +350,15 @@ declare namespace _ {
|
||||
type LodashContains1x1<T> = (collection: lodash.List<T> | lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined) => boolean;
|
||||
type LodashContains1x2<T> = (target: T) => boolean;
|
||||
interface LodashCountBy {
|
||||
<T>(iteratee: (value: string) => T): LodashCountBy1x1;
|
||||
(iteratee: lodash.__, collection: string | null | undefined): LodashCountBy1x2;
|
||||
<T>(iteratee: (value: string) => T, collection: string | null | undefined): lodash.Dictionary<number>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashCountBy2x1<T>;
|
||||
<T>(iteratee: lodash.__, collection: lodash.List<T> | null | undefined): LodashCountBy2x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashCountBy1x1<T>;
|
||||
<T>(iteratee: lodash.__, collection: lodash.List<T> | null | undefined): LodashCountBy1x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>, collection: lodash.List<T> | null | undefined): lodash.Dictionary<number>;
|
||||
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashCountBy3x2<T>;
|
||||
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashCountBy2x2<T>;
|
||||
<T extends object>(iteratee: lodash.ValueIteratee<T[keyof T]>, collection: T | null | undefined): lodash.Dictionary<number>;
|
||||
}
|
||||
type LodashCountBy1x1 = (collection: string | null | undefined) => lodash.Dictionary<number>;
|
||||
type LodashCountBy1x2 = <T>(iteratee: (value: string) => T) => lodash.Dictionary<number>;
|
||||
type LodashCountBy2x1<T> = (collection: lodash.List<T> | object | null | undefined) => lodash.Dictionary<number>;
|
||||
type LodashCountBy2x2<T> = (iteratee: lodash.ValueIteratee<T>) => lodash.Dictionary<number>;
|
||||
type LodashCountBy3x2<T> = (iteratee: lodash.ValueIteratee<T[keyof T]>) => lodash.Dictionary<number>;
|
||||
type LodashCountBy1x1<T> = (collection: lodash.List<T> | object | null | undefined) => lodash.Dictionary<number>;
|
||||
type LodashCountBy1x2<T> = (iteratee: lodash.ValueIteratee<T>) => lodash.Dictionary<number>;
|
||||
type LodashCountBy2x2<T> = (iteratee: lodash.ValueIteratee<T[keyof T]>) => lodash.Dictionary<number>;
|
||||
type LodashCreate = <T extends object, U extends object>(prototype: T) => T & U;
|
||||
interface LodashCurry {
|
||||
<T1, R>(func: (t1: T1) => R): lodash.CurriedFunction1<T1, R>;
|
||||
@@ -744,7 +739,7 @@ declare namespace _ {
|
||||
}
|
||||
type LodashExtendWith1x5<TSource> = <TObject>(object: TObject) => TObject & TSource;
|
||||
type LodashExtendWith1x6<TObject, TSource> = (customizer: lodash.AssignCustomizer) => TObject & TSource;
|
||||
type LodashStubFalse = () => boolean;
|
||||
type LodashStubFalse = () => false;
|
||||
interface LodashFill {
|
||||
(start: number): LodashFill1x1;
|
||||
(start: lodash.__, end: number): LodashFill1x2;
|
||||
@@ -1580,20 +1575,15 @@ declare namespace _ {
|
||||
type LodashGetOr4x5 = (path: lodash.PropertyPath) => any;
|
||||
type LodashGetOr4x6 = (defaultValue: any) => any;
|
||||
interface LodashGroupBy {
|
||||
(iteratee: (value: string) => lodash.NotVoid): LodashGroupBy1x1;
|
||||
(iteratee: lodash.__, collection: string | null | undefined): LodashGroupBy1x2;
|
||||
(iteratee: (value: string) => lodash.NotVoid, collection: string | null | undefined): lodash.Dictionary<string[]>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashGroupBy2x1<T>;
|
||||
<T>(iteratee: lodash.__, collection: lodash.List<T> | null | undefined): LodashGroupBy2x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashGroupBy1x1<T>;
|
||||
<T>(iteratee: lodash.__, collection: lodash.List<T> | null | undefined): LodashGroupBy1x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>, collection: lodash.List<T> | null | undefined): lodash.Dictionary<T[]>;
|
||||
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashGroupBy3x2<T>;
|
||||
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashGroupBy2x2<T>;
|
||||
<T extends object>(iteratee: lodash.ValueIteratee<T[keyof T]>, collection: T | null | undefined): lodash.Dictionary<Array<T[keyof T]>>;
|
||||
}
|
||||
type LodashGroupBy1x1 = (collection: string | null | undefined) => lodash.Dictionary<string[]>;
|
||||
type LodashGroupBy1x2 = (iteratee: (value: string) => lodash.NotVoid) => lodash.Dictionary<string[]>;
|
||||
type LodashGroupBy2x1<T> = (collection: lodash.List<T> | object | null | undefined) => lodash.Dictionary<T[]>;
|
||||
type LodashGroupBy2x2<T> = (iteratee: lodash.ValueIteratee<T>) => lodash.Dictionary<T[]>;
|
||||
type LodashGroupBy3x2<T> = (iteratee: lodash.ValueIteratee<T[keyof T]>) => lodash.Dictionary<Array<T[keyof T]>>;
|
||||
type LodashGroupBy1x1<T> = (collection: lodash.List<T> | object | null | undefined) => lodash.Dictionary<T[]>;
|
||||
type LodashGroupBy1x2<T> = (iteratee: lodash.ValueIteratee<T>) => lodash.Dictionary<T[]>;
|
||||
type LodashGroupBy2x2<T> = (iteratee: lodash.ValueIteratee<T[keyof T]>) => lodash.Dictionary<Array<T[keyof T]>>;
|
||||
interface LodashGt {
|
||||
(value: any): LodashGt1x1;
|
||||
(value: lodash.__, other: any): LodashGt1x2;
|
||||
@@ -1661,20 +1651,15 @@ declare namespace _ {
|
||||
type LodashIncludesFrom1x5 = (fromIndex: number) => boolean;
|
||||
type LodashIncludesFrom1x6<T> = (target: T) => boolean;
|
||||
interface LodashKeyBy {
|
||||
(iteratee: (value: string) => lodash.PropertyName): LodashKeyBy1x1;
|
||||
(iteratee: lodash.__, collection: string | null | undefined): LodashKeyBy1x2;
|
||||
(iteratee: (value: string) => lodash.PropertyName, collection: string | null | undefined): lodash.Dictionary<string>;
|
||||
<T>(iteratee: lodash.ValueIterateeCustom<T, lodash.PropertyName>): LodashKeyBy2x1<T>;
|
||||
<T>(iteratee: lodash.__, collection: lodash.List<T> | null | undefined): LodashKeyBy2x2<T>;
|
||||
<T>(iteratee: lodash.ValueIterateeCustom<T, lodash.PropertyName>): LodashKeyBy1x1<T>;
|
||||
<T>(iteratee: lodash.__, collection: lodash.List<T> | null | undefined): LodashKeyBy1x2<T>;
|
||||
<T>(iteratee: lodash.ValueIterateeCustom<T, lodash.PropertyName>, collection: lodash.List<T> | null | undefined): lodash.Dictionary<T>;
|
||||
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashKeyBy3x2<T>;
|
||||
<T extends object>(iteratee: lodash.__, collection: T | null | undefined): LodashKeyBy2x2<T>;
|
||||
<T extends object>(iteratee: lodash.ValueIterateeCustom<T[keyof T], lodash.PropertyName>, collection: T | null | undefined): lodash.Dictionary<T[keyof T]>;
|
||||
}
|
||||
type LodashKeyBy1x1 = (collection: string | null | undefined) => lodash.Dictionary<string>;
|
||||
type LodashKeyBy1x2 = (iteratee: (value: string) => lodash.PropertyName) => lodash.Dictionary<string>;
|
||||
type LodashKeyBy2x1<T> = (collection: lodash.List<T> | object | null | undefined) => lodash.Dictionary<T>;
|
||||
type LodashKeyBy2x2<T> = (iteratee: lodash.ValueIterateeCustom<T, lodash.PropertyName>) => lodash.Dictionary<T>;
|
||||
type LodashKeyBy3x2<T> = (iteratee: lodash.ValueIterateeCustom<T[keyof T], lodash.PropertyName>) => lodash.Dictionary<T[keyof T]>;
|
||||
type LodashKeyBy1x1<T> = (collection: lodash.List<T> | object | null | undefined) => lodash.Dictionary<T>;
|
||||
type LodashKeyBy1x2<T> = (iteratee: lodash.ValueIterateeCustom<T, lodash.PropertyName>) => lodash.Dictionary<T>;
|
||||
type LodashKeyBy2x2<T> = (iteratee: lodash.ValueIterateeCustom<T[keyof T], lodash.PropertyName>) => lodash.Dictionary<T[keyof T]>;
|
||||
interface LodashIndexOf {
|
||||
<T>(value: T): LodashIndexOf1x1<T>;
|
||||
<T>(value: lodash.__, array: lodash.List<T> | null | undefined): LodashIndexOf1x2<T>;
|
||||
@@ -3546,17 +3531,12 @@ declare namespace _ {
|
||||
type LodashSortedLastIndexOf1x2<T> = (value: T) => number;
|
||||
type LodashSortedUniq = <T>(array: lodash.List<T> | null | undefined) => T[];
|
||||
interface LodashSortedUniqBy {
|
||||
(iteratee: (value: string) => lodash.NotVoid): LodashSortedUniqBy1x1;
|
||||
(iteratee: lodash.__, array: string | null | undefined): LodashSortedUniqBy1x2;
|
||||
(iteratee: (value: string) => lodash.NotVoid, array: string | null | undefined): string[];
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashSortedUniqBy2x1<T>;
|
||||
<T>(iteratee: lodash.__, array: lodash.List<T> | null | undefined): LodashSortedUniqBy2x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashSortedUniqBy1x1<T>;
|
||||
<T>(iteratee: lodash.__, array: lodash.List<T> | null | undefined): LodashSortedUniqBy1x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>, array: lodash.List<T> | null | undefined): T[];
|
||||
}
|
||||
type LodashSortedUniqBy1x1 = (array: string | null | undefined) => string[];
|
||||
type LodashSortedUniqBy1x2 = (iteratee: (value: string) => lodash.NotVoid) => string[];
|
||||
type LodashSortedUniqBy2x1<T> = (array: lodash.List<T> | null | undefined) => T[];
|
||||
type LodashSortedUniqBy2x2<T> = (iteratee: lodash.ValueIteratee<T>) => T[];
|
||||
type LodashSortedUniqBy1x1<T> = (array: lodash.List<T> | null | undefined) => T[];
|
||||
type LodashSortedUniqBy1x2<T> = (iteratee: lodash.ValueIteratee<T>) => T[];
|
||||
interface LodashSplit {
|
||||
(separator: RegExp|string): LodashSplit1x1;
|
||||
(separator: lodash.__, string: string): LodashSplit1x2;
|
||||
@@ -3583,7 +3563,7 @@ declare namespace _ {
|
||||
type LodashStubArray = () => any[];
|
||||
type LodashStubObject = () => any;
|
||||
type LodashStubString = () => string;
|
||||
type LodashStubTrue = () => boolean;
|
||||
type LodashStubTrue = () => true;
|
||||
interface LodashSubtract {
|
||||
(minuend: number): LodashSubtract1x1;
|
||||
(minuend: lodash.__, subtrahend: number): LodashSubtract1x2;
|
||||
@@ -3900,17 +3880,12 @@ declare namespace _ {
|
||||
type LodashUnionWith1x6<T> = (comparator: lodash.Comparator<T>) => T[];
|
||||
type LodashUniq = <T>(array: lodash.List<T> | null | undefined) => T[];
|
||||
interface LodashUniqBy {
|
||||
(iteratee: (value: string) => lodash.NotVoid): LodashUniqBy1x1;
|
||||
(iteratee: lodash.__, array: string | null | undefined): LodashUniqBy1x2;
|
||||
(iteratee: (value: string) => lodash.NotVoid, array: string | null | undefined): string[];
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashUniqBy2x1<T>;
|
||||
<T>(iteratee: lodash.__, array: lodash.List<T> | null | undefined): LodashUniqBy2x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>): LodashUniqBy1x1<T>;
|
||||
<T>(iteratee: lodash.__, array: lodash.List<T> | null | undefined): LodashUniqBy1x2<T>;
|
||||
<T>(iteratee: lodash.ValueIteratee<T>, array: lodash.List<T> | null | undefined): T[];
|
||||
}
|
||||
type LodashUniqBy1x1 = (array: string | null | undefined) => string[];
|
||||
type LodashUniqBy1x2 = (iteratee: (value: string) => lodash.NotVoid) => string[];
|
||||
type LodashUniqBy2x1<T> = (array: lodash.List<T> | null | undefined) => T[];
|
||||
type LodashUniqBy2x2<T> = (iteratee: lodash.ValueIteratee<T>) => T[];
|
||||
type LodashUniqBy1x1<T> = (array: lodash.List<T> | null | undefined) => T[];
|
||||
type LodashUniqBy1x2<T> = (iteratee: lodash.ValueIteratee<T>) => T[];
|
||||
type LodashUniqueId = (prefix: string) => string;
|
||||
interface LodashUniqWith {
|
||||
<T>(comparator: lodash.Comparator<T>): LodashUniqWith1x1<T>;
|
||||
|
||||
@@ -1399,35 +1399,33 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
|
||||
// _.sortedUniqBy
|
||||
{
|
||||
const list: _.List<AbcObject> | null | undefined = anything;
|
||||
const stringIterator = (value: string, index: number, collection: string) => "";
|
||||
const listIterator = (value: AbcObject, index: number, collection: _.List<AbcObject>) => 0;
|
||||
const stringIterator2 = (value: string) => "";
|
||||
const listIterator2 = (value: AbcObject) => 0;
|
||||
const stringIterator = (value: string) => "";
|
||||
const valueIterator = (value: AbcObject) => 0;
|
||||
|
||||
_.uniqBy("abc", stringIterator); // $ExpectType string[]
|
||||
_.uniqBy(list, listIterator); // $ExpectType AbcObject[]
|
||||
_.uniqBy(list, valueIterator); // $ExpectType AbcObject[]
|
||||
_.uniqBy(list, "a"); // $ExpectType AbcObject[]
|
||||
_(list).uniqBy(listIterator); // $ExpectType LoDashImplicitWrapper<AbcObject[]>
|
||||
_(list).uniqBy(valueIterator); // $ExpectType LoDashImplicitWrapper<AbcObject[]>
|
||||
_(list).uniqBy("a"); // $ExpectType LoDashImplicitWrapper<AbcObject[]>
|
||||
_.chain(list).uniqBy(listIterator); // $ExpectType LoDashExplicitWrapper<AbcObject[]>
|
||||
_.chain(list).uniqBy(valueIterator); // $ExpectType LoDashExplicitWrapper<AbcObject[]>
|
||||
_.chain(list).uniqBy("a"); // $ExpectType LoDashExplicitWrapper<AbcObject[]>
|
||||
|
||||
fp.uniqBy(stringIterator2, "abc"); // $ExpectType string[]
|
||||
fp.uniqBy(listIterator2, list); // $ExpectType AbcObject[]
|
||||
fp.uniqBy(listIterator2)(list); // $ExpectType AbcObject[]
|
||||
fp.uniqBy(stringIterator, "abc"); // $ExpectType string[]
|
||||
fp.uniqBy(valueIterator, list); // $ExpectType AbcObject[]
|
||||
fp.uniqBy(valueIterator)(list); // $ExpectType AbcObject[]
|
||||
fp.uniqBy("a", list); // $ExpectType AbcObject[]
|
||||
|
||||
_.sortedUniqBy("abc", stringIterator); // $ExpectType string[]
|
||||
_.sortedUniqBy(list, listIterator); // $ExpectType AbcObject[]
|
||||
_.sortedUniqBy(list, valueIterator); // $ExpectType AbcObject[]
|
||||
_.sortedUniqBy(list, "a"); // $ExpectType AbcObject[]
|
||||
_(list).sortedUniqBy(listIterator); // $ExpectType LoDashImplicitWrapper<AbcObject[]>
|
||||
_(list).sortedUniqBy(valueIterator); // $ExpectType LoDashImplicitWrapper<AbcObject[]>
|
||||
_(list).sortedUniqBy("a"); // $ExpectType LoDashImplicitWrapper<AbcObject[]>
|
||||
_.chain(list).sortedUniqBy(listIterator); // $ExpectType LoDashExplicitWrapper<AbcObject[]>
|
||||
_.chain(list).sortedUniqBy(valueIterator); // $ExpectType LoDashExplicitWrapper<AbcObject[]>
|
||||
_.chain(list).sortedUniqBy("a"); // $ExpectType LoDashExplicitWrapper<AbcObject[]>
|
||||
|
||||
fp.sortedUniqBy(stringIterator2, "abc"); // $ExpectType string[]
|
||||
fp.sortedUniqBy(listIterator2, list); // $ExpectType AbcObject[]
|
||||
fp.sortedUniqBy(listIterator2)(list); // $ExpectType AbcObject[]
|
||||
fp.sortedUniqBy(stringIterator, "abc"); // $ExpectType string[]
|
||||
fp.sortedUniqBy(valueIterator, list); // $ExpectType AbcObject[]
|
||||
fp.sortedUniqBy(valueIterator)(list); // $ExpectType AbcObject[]
|
||||
fp.sortedUniqBy("a", list); // $ExpectType AbcObject[]
|
||||
}
|
||||
|
||||
@@ -1725,26 +1723,24 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
|
||||
const dictionary: _.Dictionary<AbcObject> | null | undefined = anything;
|
||||
const numericDictionary: _.NumericDictionary<AbcObject> | null | undefined = anything;
|
||||
|
||||
const stringIterator = (value: string, index: number, collection: string) => 1;
|
||||
const listIterator = (value: AbcObject, index: number, collection: _.List<AbcObject>) => 1;
|
||||
const dictionaryIterator = (value: AbcObject, key: string, collection: _.Dictionary<AbcObject>) => 1;
|
||||
const numericDictionaryIterator = (value: AbcObject, key: string, collection: _.NumericDictionary<AbcObject>) => 1;
|
||||
const stringIterator = (value: string) => 1;
|
||||
const valueIterator = (value: AbcObject) => 1;
|
||||
|
||||
_.countBy(""); // $ExpectType Dictionary<number>
|
||||
_.countBy("", stringIterator); // $ExpectType Dictionary<number>
|
||||
|
||||
_.countBy(list); // $ExpectType Dictionary<number>
|
||||
_.countBy(list, listIterator); // $ExpectType Dictionary<number>
|
||||
_.countBy(list, valueIterator); // $ExpectType Dictionary<number>
|
||||
_.countBy(list, ""); // $ExpectType Dictionary<number>
|
||||
_.countBy(list, { a: 42 }); // $ExpectType Dictionary<number>
|
||||
|
||||
_.countBy(dictionary); // $ExpectType Dictionary<number>
|
||||
_.countBy(dictionary, dictionaryIterator); // $ExpectType Dictionary<number>
|
||||
_.countBy(dictionary, valueIterator); // $ExpectType Dictionary<number>
|
||||
_.countBy(dictionary, ""); // $ExpectType Dictionary<number>
|
||||
_.countBy(dictionary, { a: 42 }); // $ExpectType Dictionary<number>
|
||||
|
||||
_.countBy(numericDictionary); // $ExpectType Dictionary<number>
|
||||
_.countBy(numericDictionary, numericDictionaryIterator); // $ExpectType Dictionary<number>
|
||||
_.countBy(numericDictionary, valueIterator); // $ExpectType Dictionary<number>
|
||||
_.countBy(numericDictionary, ""); // $ExpectType Dictionary<number>
|
||||
_.countBy(numericDictionary, { a: 42 }); // $ExpectType Dictionary<number>
|
||||
|
||||
@@ -1752,17 +1748,17 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
|
||||
_("").countBy(stringIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
|
||||
_(list).countBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(list).countBy(listIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(list).countBy(valueIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(list).countBy(""); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(list).countBy({ a: 42 }); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
|
||||
_(dictionary).countBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(dictionary).countBy(dictionaryIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(dictionary).countBy(valueIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(dictionary).countBy(""); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(dictionary).countBy({ a: 42 }); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
|
||||
_(numericDictionary).countBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(numericDictionary).countBy(numericDictionaryIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(numericDictionary).countBy(valueIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(numericDictionary).countBy(""); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
_(numericDictionary).countBy({ a: 42 }); // $ExpectType LoDashImplicitWrapper<Dictionary<number>>
|
||||
|
||||
@@ -1770,30 +1766,28 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
|
||||
_.chain("").countBy(stringIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
|
||||
_.chain(list).countBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(list).countBy(listIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(list).countBy(valueIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(list).countBy(""); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(list).countBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
|
||||
_.chain(dictionary).countBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(dictionary).countBy(dictionaryIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(dictionary).countBy(valueIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(dictionary).countBy(""); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(dictionary).countBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
|
||||
_.chain(numericDictionary).countBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(numericDictionary).countBy(numericDictionaryIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(numericDictionary).countBy(valueIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(numericDictionary).countBy(""); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
_.chain(numericDictionary).countBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<Dictionary<number>>
|
||||
|
||||
const stringIterator2 = (value: string) => 1;
|
||||
const listIterator2 = (value: AbcObject) => 1;
|
||||
fp.countBy(stringIterator2, ""); // $ExpectType Dictionary<number>
|
||||
fp.countBy(stringIterator2)(""); // $ExpectType Dictionary<number>
|
||||
fp.countBy(listIterator2, list); // $ExpectType Dictionary<number>
|
||||
fp.countBy(stringIterator, ""); // $ExpectType Dictionary<number>
|
||||
fp.countBy(stringIterator)(""); // $ExpectType Dictionary<number>
|
||||
fp.countBy(valueIterator, list); // $ExpectType Dictionary<number>
|
||||
fp.countBy("", list); // $ExpectType Dictionary<number>
|
||||
fp.countBy({ a: 42 }, list); // $ExpectType Dictionary<number>
|
||||
fp.countBy(listIterator2, dictionary); // $ExpectType Dictionary<number>
|
||||
fp.countBy(valueIterator, dictionary); // $ExpectType Dictionary<number>
|
||||
fp.countBy({ a: 42 }, dictionary); // $ExpectType Dictionary<number>
|
||||
fp.countBy(listIterator2, numericDictionary); // $ExpectType Dictionary<number>
|
||||
fp.countBy(valueIterator, numericDictionary); // $ExpectType Dictionary<number>
|
||||
fp.countBy({ a: 42 }, numericDictionary); // $ExpectType Dictionary<number>
|
||||
}
|
||||
|
||||
@@ -2656,41 +2650,39 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
|
||||
const list: _.List<AbcObject> | null | undefined = [] as any;
|
||||
const dictionary: _.Dictionary<AbcObject> | null | undefined = anything;
|
||||
|
||||
const stringIterator = (char: string, index: number, string: string) => 0;
|
||||
const listIterator = (value: AbcObject, index: number, collection: _.List<AbcObject>) => 0;
|
||||
const dictionaryIterator = (value: AbcObject, key: string, collection: _.Dictionary<AbcObject>) => 0;
|
||||
const stringIterator = (char: string) => 0;
|
||||
const valueIterator = (value: AbcObject) => 0;
|
||||
|
||||
_.groupBy(""); // $ExpectType Dictionary<string[]>
|
||||
_.groupBy("", stringIterator); // $ExpectType Dictionary<string[]>
|
||||
_.groupBy(list); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(list, listIterator); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(list, valueIterator); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(list, "a"); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(list, { a: 42 }); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(dictionary); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(dictionary, dictionaryIterator); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(dictionary, valueIterator); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(dictionary, ""); // $ExpectType Dictionary<AbcObject[]>
|
||||
_.groupBy(dictionary, { a: 42 }); // $ExpectType Dictionary<AbcObject[]>
|
||||
|
||||
_("").groupBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<string[]>>
|
||||
_("").groupBy((char: string, index: number, string: ArrayLike<string>) => 0); // $ExpectType LoDashImplicitWrapper<Dictionary<string[]>>
|
||||
_("").groupBy(stringIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<string[]>>
|
||||
_(list).groupBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(list).groupBy(listIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(list).groupBy(valueIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(list).groupBy(""); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(list).groupBy({ a: 42 }); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(dictionary).groupBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(dictionary).groupBy(dictionaryIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(dictionary).groupBy(valueIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(dictionary).groupBy(""); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_(dictionary).groupBy({ a: 42 }); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject[]>>
|
||||
|
||||
_.chain("").groupBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<string[]>>
|
||||
_.chain("").groupBy((char: string, index: number, string: ArrayLike<string>) => 0); // $ExpectType LoDashExplicitWrapper<Dictionary<string[]>>
|
||||
_.chain("").groupBy(stringIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<string[]>>
|
||||
_.chain(list).groupBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(list).groupBy(listIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(list).groupBy(valueIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(list).groupBy(""); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(list).groupBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(dictionary).groupBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(dictionary).groupBy(dictionaryIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(dictionary).groupBy(valueIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(dictionary).groupBy(""); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
_.chain(dictionary).groupBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject[]>>
|
||||
|
||||
@@ -2741,57 +2733,54 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
|
||||
const dictionary: _.Dictionary<AbcObject> | null | undefined = anything;
|
||||
const numericDictionary: _.NumericDictionary<AbcObject> | null | undefined = anything;
|
||||
|
||||
const stringIterator = (value: string, index: number, collection: string) => "a";
|
||||
const listIterator = (value: AbcObject, index: number, collection: _.List<AbcObject>) => 1;
|
||||
const dictionaryIterator = (value: AbcObject, key: string, collection: _.Dictionary<AbcObject>) => Symbol.name;
|
||||
const numericDictionaryIterator = (value: AbcObject, key: string, collection: _.NumericDictionary<AbcObject>) => "a";
|
||||
const stringIterator = (value: string) => "a";
|
||||
const valueIterator = (value: AbcObject) => 1;
|
||||
|
||||
_.keyBy("abcd"); // $ExpectType Dictionary<string>
|
||||
_.keyBy("abcd", stringIterator); // $ExpectType Dictionary<string>
|
||||
_.keyBy(list); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(list, listIterator); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(list, valueIterator); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(list, "a"); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(list, { a: 42 }); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(dictionary); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(dictionary, dictionaryIterator); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(dictionary, valueIterator); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(dictionary, "a"); // $ExpectType Dictionary<AbcObject>
|
||||
_.keyBy(dictionary, { a: 42 }); // $ExpectType Dictionary<AbcObject>
|
||||
// These fail in TS 2.4
|
||||
// _.keyBy(numericDictionary); // Dictionary<AbcObject>
|
||||
// _.keyBy(numericDictionary, numericDictionaryIterator); // Dictionary<AbcObject>
|
||||
// _.keyBy(numericDictionary, valueIterator); // Dictionary<AbcObject>
|
||||
// _.keyBy(numericDictionary, "a"); // Dictionary<AbcObject>
|
||||
// _.keyBy(numericDictionary, { a: 42 }); // Dictionary<AbcObject>
|
||||
|
||||
_("abcd").keyBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<string>>
|
||||
_("abcd").keyBy(stringIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<string>>
|
||||
_(list).keyBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(list).keyBy(listIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(list).keyBy(valueIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(list).keyBy("a"); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(list).keyBy({ a: 42 }); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(dictionary).keyBy(); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(dictionary).keyBy(dictionaryIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(dictionary).keyBy(valueIterator); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(dictionary).keyBy("a"); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
_(dictionary).keyBy({ a: 42 }); // $ExpectType LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
// These fail in TS 2.4
|
||||
// _(numericDictionary).keyBy(); // LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
// _(numericDictionary).keyBy(numericDictionaryIterator); // LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
// _(numericDictionary).keyBy(valueIterator); // LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
// _(numericDictionary).keyBy("a"); // LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
// _(numericDictionary).keyBy({ a: 42 }); // LoDashImplicitWrapper<Dictionary<AbcObject>>
|
||||
|
||||
_.chain("abcd").keyBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<string>>
|
||||
_.chain("abcd").keyBy(stringIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<string>>
|
||||
_.chain(list).keyBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(list).keyBy(listIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(list).keyBy(valueIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(list).keyBy("a"); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(list).keyBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(dictionary).keyBy(); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(dictionary).keyBy(dictionaryIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(dictionary).keyBy(valueIterator); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(dictionary).keyBy("a"); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
_.chain(dictionary).keyBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
// These fail in TS 2.4
|
||||
// _.chain(numericDictionary).keyBy(); // LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
// _.chain(numericDictionary).keyBy(numericDictionaryIterator); // LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
// _.chain(numericDictionary).keyBy(valueIterator); // LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
// _.chain(numericDictionary).keyBy("a"); // LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
// _.chain(numericDictionary).keyBy({ a: 42 }); // LoDashExplicitWrapper<Dictionary<AbcObject>>
|
||||
|
||||
@@ -3085,27 +3074,34 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType LoDashExplicitWrapper<number
|
||||
}
|
||||
const initial: ABC = { a: 1, b: 2, c: 3 };
|
||||
|
||||
_.reduce([1, 2, 3], (sum: number, num: number) => sum + num); // $ExpectType number | undefined
|
||||
// $ExpectType number | undefined
|
||||
_.reduce([1, 2, 3], (sum, curr, key, coll) => {
|
||||
sum; // $ExpectType number
|
||||
curr; // $ExpectType number
|
||||
key; // $ExpectType number
|
||||
coll; // $ExpectType number[]
|
||||
return sum + curr;
|
||||
});
|
||||
_.reduce(null, (sum: number, num: number) => sum + num); // $ExpectType number | undefined
|
||||
_.reduce({ a: 1, b: 2, c: 3 }, (r: ABC, num: number, key: string) => r, initial); // $ExpectType ABC
|
||||
|
||||
_([1, 2, 3]).reduce((sum: number, num: number) => sum + num); // $ExpectType number | undefined
|
||||
_([1, 2, 3]).reduce((sum, num) => sum + num); // $ExpectType number | undefined
|
||||
_({ a: 1, b: 2, c: 3 }).reduce((r: ABC, num: number, key: string) => r, initial); // $ExpectType ABC
|
||||
|
||||
_.chain([1, 2, 3]).reduce((sum: number, num: number) => sum + num); // $ExpectType LoDashExplicitWrapper<number | undefined>
|
||||
_.chain([1, 2, 3]).reduce((sum, num) => sum + num); // $ExpectType LoDashExplicitWrapper<number | undefined>
|
||||
_.chain({ a: 1, b: 2, c: 3 }).reduce((r: ABC, num: number, key: string) => r, initial); // $ExpectType LoDashExplicitWrapper<ABC>
|
||||
|
||||
fp.reduce((s: string, num: number) => s + num, "", [1, 2, 3]); // $ExpectType string
|
||||
fp.reduce((s: string, num: number) => s + num)("")([1, 2, 3]); // $ExpectType string
|
||||
|
||||
_.reduceRight([1, 2, 3], (sum: number, num: number) => sum + num); // $ExpectType number | undefined
|
||||
_.reduceRight([1, 2, 3], (sum, num) => sum + num); // $ExpectType number | undefined
|
||||
_.reduceRight(null, (sum: number, num: number) => sum + num); // $ExpectType number | undefined
|
||||
_.reduceRight({ a: 1, b: 2, c: 3 }, (r: ABC, num: number, key: string) => r, initial); // $ExpectType ABC
|
||||
|
||||
_([1, 2, 3]).reduceRight((sum: number, num: number) => sum + num); // $ExpectType number | undefined
|
||||
_([1, 2, 3]).reduceRight((sum, num) => sum + num); // $ExpectType number | undefined
|
||||
_({ a: 1, b: 2, c: 3 }).reduceRight((r: ABC, num: number, key: string) => r, initial); // $ExpectType ABC
|
||||
|
||||
_.chain([1, 2, 3]).reduceRight((sum: number, num: number) => sum + num); // $ExpectType LoDashExplicitWrapper<number | undefined>
|
||||
_.chain([1, 2, 3]).reduceRight((sum, num) => sum + num); // $ExpectType LoDashExplicitWrapper<number | undefined>
|
||||
_.chain({ a: 1, b: 2, c: 3 }).reduceRight((r: ABC, num: number, key: string) => r, initial); // $ExpectType LoDashExplicitWrapper<ABC>
|
||||
|
||||
fp.reduceRight((num: number, s: string) => s + num, "", [1, 2, 3]); // $ExpectType string
|
||||
@@ -4886,29 +4882,28 @@ fp.now(); // $ExpectType number
|
||||
{
|
||||
const list: ArrayLike<AbcObject> = anything;
|
||||
|
||||
const listIterator = (value: AbcObject, index: number, collection: ArrayLike<AbcObject>) => 0;
|
||||
const valueIterator = (value: AbcObject) => 0;
|
||||
|
||||
_.maxBy(list, listIterator); // $ExpectType AbcObject | undefined
|
||||
_.maxBy(list, valueIterator); // $ExpectType AbcObject | undefined
|
||||
_.maxBy(list, "a"); // $ExpectType AbcObject | undefined
|
||||
_.maxBy(list, { a: 42 }); // $ExpectType AbcObject | undefined
|
||||
_(list).maxBy(listIterator); // $ExpectType AbcObject | undefined
|
||||
_(list).maxBy(valueIterator); // $ExpectType AbcObject | undefined
|
||||
_(list).maxBy("a"); // $ExpectType AbcObject | undefined
|
||||
_(list).maxBy({ a: 42 }); // $ExpectType AbcObject | undefined
|
||||
_.chain(list).maxBy(listIterator); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
_.chain(list).maxBy(valueIterator); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
_.chain(list).maxBy("a"); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
_.chain(list).maxBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
fp.maxBy(valueIterator)(list); // $ExpectType AbcObject | undefined
|
||||
fp.maxBy("a", list); // $ExpectType AbcObject | undefined
|
||||
fp.maxBy({ a: 42 }, list); // $ExpectType AbcObject | undefined
|
||||
|
||||
_.minBy(list, listIterator); // $ExpectType AbcObject | undefined
|
||||
_.minBy(list, valueIterator); // $ExpectType AbcObject | undefined
|
||||
_.minBy(list, "a"); // $ExpectType AbcObject | undefined
|
||||
_.minBy(list, { a: 42 }); // $ExpectType AbcObject | undefined
|
||||
_(list).minBy(listIterator); // $ExpectType AbcObject | undefined
|
||||
_(list).minBy(valueIterator); // $ExpectType AbcObject | undefined
|
||||
_(list).minBy("a"); // $ExpectType AbcObject | undefined
|
||||
_(list).minBy({ a: 42 }); // $ExpectType AbcObject | undefined
|
||||
_.chain(list).minBy(listIterator); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
_.chain(list).minBy(valueIterator); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
_.chain(list).minBy("a"); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
_.chain(list).minBy({ a: 42 }); // $ExpectType LoDashExplicitWrapper<AbcObject | undefined>
|
||||
fp.minBy(valueIterator)(list); // $ExpectType AbcObject | undefined
|
||||
@@ -7139,10 +7134,10 @@ fp.now(); // $ExpectType number
|
||||
|
||||
// _.stubFalse
|
||||
{
|
||||
_.stubFalse(); // $ExpectType boolean
|
||||
_(anything).stubFalse(); // $ExpectType boolean
|
||||
_.chain(anything).stubFalse(); // $ExpectType LoDashExplicitWrapper<boolean>
|
||||
fp.stubFalse(); // $ExpectType boolean
|
||||
_.stubFalse(); // $ExpectType false
|
||||
_(anything).stubFalse(); // $ExpectType false
|
||||
_.chain(anything).stubFalse(); // $ExpectType LoDashExplicitWrapper<false>
|
||||
fp.stubFalse(); // $ExpectType false
|
||||
}
|
||||
|
||||
// _.stubObject
|
||||
@@ -7163,10 +7158,10 @@ fp.now(); // $ExpectType number
|
||||
|
||||
// _.stubTrue
|
||||
{
|
||||
_.stubTrue(); // $ExpectType boolean
|
||||
_(anything).stubTrue(); // $ExpectType boolean
|
||||
_.chain(anything).stubTrue(); // $ExpectType LoDashExplicitWrapper<boolean>
|
||||
fp.stubTrue(); // $ExpectType boolean
|
||||
_.stubTrue(); // $ExpectType true
|
||||
_(anything).stubTrue(); // $ExpectType true
|
||||
_.chain(anything).stubTrue(); // $ExpectType LoDashExplicitWrapper<true>
|
||||
fp.stubTrue(); // $ExpectType true
|
||||
}
|
||||
|
||||
// _.times
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
You should not modify these scripts directly - you should use a script to re-generate them (see below).
|
||||
- `scripts` directory: contains code generation scripts.
|
||||
- Before running any scripts, run `npm install` in this directory (it contains its own `package.json`).
|
||||
- Most notable script is `npm run fp`, which re-generates all of the `fp` files.
|
||||
- Most notable script is `npm run generate`, which re-generates all of the `fp` files and `lowdb` wrapper extensions.
|
||||
- `v3` directory: contains types for lodash v3.
|
||||
|
||||
## Different ways people might use lodash
|
||||
@@ -38,7 +38,7 @@
|
||||
## Before creating a PR
|
||||
|
||||
- For every function you modify, don't forget to update the corresponding wrapper functions.
|
||||
- Re-generate the `fp` types by opening a terminal in the `scripts` directory and running `npm run fp`.
|
||||
- Re-generate the `fp` types by opening a terminal in the `scripts` directory and running `npm run generate`.
|
||||
- Note that this directory has its own `package.json`, so you'll need to run `npm install` first if you haven't already.
|
||||
- Back at the root directory, do `npm run lint lodash` and make sure there are no errors.
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import convert from "lodash/fp/convert";
|
||||
import path from "path";
|
||||
import { readFile, getLineBreak, tab, getLineNumber } from "./utils";
|
||||
|
||||
interface Definition {
|
||||
name: string;
|
||||
@@ -45,10 +46,8 @@ interface TypeParam {
|
||||
|
||||
let lineBreak = "\n";
|
||||
async function main() {
|
||||
lineBreak = await getLineBreak();
|
||||
const commonTypes: string[] = [];
|
||||
const tsconfigPath = path.join("..", "tsconfig.json");
|
||||
const tsconfigFile = await readFile(tsconfigPath);
|
||||
lineBreak = _.find(["\r\n", "\n", "\r"], x => tsconfigFile.includes(x)) || "\n";
|
||||
|
||||
// Read each function definition and fp-ify it
|
||||
const subfolders = ["common"];
|
||||
@@ -106,7 +105,7 @@ async function main() {
|
||||
const fpFile = [
|
||||
"// AUTO-GENERATED: do not modify this file directly.",
|
||||
"// If you need to make changes, modify generate-fp.ts (if necessary), then open a terminal in types/lodash/scripts, and do:",
|
||||
"// npm run fp",
|
||||
"// npm install && npm run generate",
|
||||
"",
|
||||
'import lodash = require("./index");',
|
||||
"",
|
||||
@@ -130,6 +129,8 @@ async function main() {
|
||||
});
|
||||
|
||||
// Make sure the generated files are listed in tsconfig.json, so they are included in the lint checks
|
||||
const tsconfigPath = path.join("..", "tsconfig.json");
|
||||
const tsconfigFile = await readFile(tsconfigPath);
|
||||
const tsconfig = tsconfigFile.split(lineBreak).filter(row => !row.includes("fp/") || row.includes("fp/convert.d.ts"));
|
||||
const newRows = interfaceGroups.map(g => ` "fp/${g.functionName}.d.ts",`)
|
||||
.concat(["__", "placeholder"].map(p => ` "fp/${p}.d.ts",`));
|
||||
@@ -146,22 +147,6 @@ async function main() {
|
||||
});
|
||||
}
|
||||
|
||||
function readFile(filePath: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
fs.readFile(filePath, "utf8", (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(data);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function processDefinitions(filePaths: string[], commonTypes: string[]): Promise<InterfaceGroup[]> {
|
||||
const builder: { [name: string]: (...args: number[][]) => () => Interface[] } = {};
|
||||
const unconvertedBuilder: { [name: string]: (...args: number[][]) => () => Interface[] } = {};
|
||||
@@ -255,7 +240,6 @@ async function parseFile(filePath: string, commonTypes: string[]): Promise<Defin
|
||||
definitons.push(...parsedDefinitions);
|
||||
lodashStaticMatch = lodashStaticRegExp.exec(definitionString);
|
||||
}
|
||||
const __test = definitons.filter(d => !_.isEmpty(d.constants));
|
||||
return definitons;
|
||||
}
|
||||
|
||||
@@ -899,15 +883,6 @@ function getPreviousLine(s: string, index: number): string {
|
||||
return s.substring(bol + 1, eol);
|
||||
}
|
||||
|
||||
function getLineNumber(fileContents: string, index: number) {
|
||||
return fileContents.substring(0, index).split(lineBreak).length + 1;
|
||||
}
|
||||
|
||||
function tab(s: string, count: number) {
|
||||
const prepend: string = " ".repeat(count * 4);
|
||||
return (s[0] === "\n" || s[0] === "\r" ? "" : prepend) + s.replace(/(?:\r\n|\n|\r)(.)/g, `${lineBreak}${prepend}$1`);
|
||||
}
|
||||
|
||||
function indexOfAny(source: string, values: string[], position?: number): number {
|
||||
const indexes: number[] = [];
|
||||
for (const value of values) {
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
// Script for converting the lodash types into functional programming (FP) format.
|
||||
// The convertion is done based on this guide: https://github.com/lodash/lodash/wiki/FP-Guide
|
||||
|
||||
// Assumptions:
|
||||
// - All functions are defined in one of the files in the "common" subfolder
|
||||
// - All functions are defined inside of the LoDashStatic interface (although functions like _.partial may refer to another interface in the same file)
|
||||
// - Consistent indentation is used for the start and end of the above interface
|
||||
// - Consistent spacing is used for interface definitions: interface MyInterface {
|
||||
// - Consistent line breaks (\n, \r, or \r\n) are used in all files
|
||||
// - All overloads of a given function are defined in the same file
|
||||
|
||||
import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import path from "path";
|
||||
import { getLineBreak, getLineNumber } from "./utils";
|
||||
|
||||
interface Definition {
|
||||
name: string;
|
||||
overloads: Overload[];
|
||||
constants: string[];
|
||||
jsdoc: string;
|
||||
}
|
||||
interface InterfaceGroup {
|
||||
functionName: string;
|
||||
interfaces: Interface[];
|
||||
}
|
||||
interface Interface {
|
||||
name: string;
|
||||
typeParams: TypeParam[];
|
||||
overloads: Overload[];
|
||||
constants: string[];
|
||||
}
|
||||
interface Overload {
|
||||
typeParams: TypeParam[];
|
||||
params: string[];
|
||||
returnType: string;
|
||||
jsdoc: string;
|
||||
tslintDisable?: string;
|
||||
}
|
||||
interface TypeParam {
|
||||
name: string;
|
||||
extends?: string;
|
||||
equals?: string;
|
||||
}
|
||||
|
||||
// Get the correct line break for the current OS (git for windows will generally convert \n to \r\n during checkout)
|
||||
let lineBreak = "\n";
|
||||
async function main() {
|
||||
lineBreak = await getLineBreak();
|
||||
const commonTypes: string[] = [];
|
||||
const tsconfigPath = path.join("..", "tsconfig.json");
|
||||
|
||||
const subfolders = ["common"];
|
||||
const promises: Array<Promise<string[]>> = [];
|
||||
for (const subfolder of subfolders) {
|
||||
promises.push(new Promise<string[]>((resolve, reject) => {
|
||||
fs.readdir(path.join("..", subfolder), (err, files) => {
|
||||
if (err) {
|
||||
console.error(`failed to list directory contents for '${subfolder}': `, err);
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
const filePaths = files.map(f => path.join("..", subfolder, f));
|
||||
try {
|
||||
resolve(processDefinitions(filePaths, commonTypes));
|
||||
} catch (e) {
|
||||
console.error(`failed to process files in '${subfolder}': `, e);
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
let functions: string;
|
||||
try {
|
||||
functions = _.flatten(await Promise.all(promises)).join(lineBreak);
|
||||
} catch (err) {
|
||||
console.error("Failed to parse all functions: ", err);
|
||||
return;
|
||||
}
|
||||
_.pull(commonTypes, "LoDashExplicitWrapper");
|
||||
const commonTypeSearch = new RegExp(`\\b(${commonTypes.join("|")})\\b`, "g");
|
||||
functions = functions.replace(commonTypeSearch, "_.$1");
|
||||
const syncFunctions = functions.replace(/\bLoDashExplicitWrapper\b/g, "LoDashExplicitSyncWrapper");
|
||||
const asyncFunctions = functions.replace(/\bLoDashExplicitWrapper\b/g, "LoDashExplicitAsyncWrapper");
|
||||
|
||||
const lodashFile = [
|
||||
"// AUTO-GENERATED: do not modify this file directly.",
|
||||
"// If you need to make changes, modify types/lodash/scripts/generate-lowdb.ts (if necessary), then open a terminal in types/lodash/scripts, and do:",
|
||||
"// npm install && npm run generate",
|
||||
"",
|
||||
'import _ = require("lodash");',
|
||||
'declare module "./index" {',
|
||||
" interface LoDashExplicitSyncWrapper<TValue> {",
|
||||
syncFunctions, // TODO: write sync?
|
||||
" }",
|
||||
"",
|
||||
" interface LoDashExplicitAsyncWrapper<TValue> {",
|
||||
asyncFunctions, // TODO: write async?
|
||||
" }",
|
||||
"}",
|
||||
"",
|
||||
].join(lineBreak);
|
||||
const lodashFilePath = path.resolve(__dirname, "..", "..", "lowdb", "_lodash.d.ts");
|
||||
fs.writeFile(lodashFilePath, lodashFile, (err) => {
|
||||
if (err)
|
||||
console.error(`Failed to write ${lodashFilePath}: `, err);
|
||||
});
|
||||
}
|
||||
|
||||
function readFile(filePath: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
fs.readFile(filePath, "utf8", (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(data);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function processDefinitions(filePaths: string[], commonTypes: string[]): Promise<string[]> {
|
||||
const functions: string[] = [];
|
||||
for (const filePath of filePaths)
|
||||
functions.push(...await parseFile(filePath, commonTypes));
|
||||
return functions;
|
||||
}
|
||||
|
||||
async function parseFile(filePath: string, commonTypes: string[]): Promise<string[]> {
|
||||
const definitionString = await readFile(filePath);
|
||||
const newCommonTypeRegExp = / (?:type|interface) ([A-Za-z0-9_]+)/g;
|
||||
let newCommonType = newCommonTypeRegExp.exec(definitionString);
|
||||
while (newCommonType) {
|
||||
if (!commonTypes.includes(newCommonType[1]))
|
||||
commonTypes.push(newCommonType[1]);
|
||||
newCommonType = newCommonTypeRegExp.exec(definitionString);
|
||||
}
|
||||
|
||||
const functions: string[] = [];
|
||||
const lodashWrapperRegExp = /( *)interface +LoDashExplicitWrapper<\w+> *(?:extends .+)? *{/g;
|
||||
let lodashWrapperMatch = lodashWrapperRegExp.exec(definitionString);
|
||||
while (lodashWrapperMatch) {
|
||||
const startIndex = definitionString.indexOf(lineBreak, lodashWrapperMatch.index) + lineBreak.length;
|
||||
const endIndex = definitionString.indexOf(`${lineBreak}${lodashWrapperMatch[1]}}`, startIndex);
|
||||
if (endIndex === -1) {
|
||||
const lineNumber = getLineNumber(definitionString, startIndex);
|
||||
console.warn(`Failed to find end of interface 'LoDashExplicitWrapper' (starting at ${filePath} line ${lineNumber}).`);
|
||||
break;
|
||||
}
|
||||
let functionString = definitionString.substring(startIndex, endIndex);
|
||||
// Remove comments since they're generally useless (e.g. @see XXXX)
|
||||
functionString = functionString.replace(/ *\/\*\*[\s\S]+?\*\/(?:\r\n|\n|\r)/g, "");
|
||||
functionString = functionString.replace(/(?:(\r\n){2,}|(\n){2,}|(\r){2,})/g, "$1$2$3");
|
||||
functions.push(functionString);
|
||||
lodashWrapperMatch = lodashWrapperRegExp.exec(definitionString);
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -3,7 +3,9 @@
|
||||
"name": "lodash-scripts",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"fp": "ts-node generate-fp"
|
||||
"generate": "ts-node generate-fp && ts-node generate-lowdb",
|
||||
"fp": "ts-node generate-fp",
|
||||
"lowdb": "ts-node generate-lowdb"
|
||||
},
|
||||
"devDependencies": {
|
||||
"lodash": "^4.17.4",
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import path from "path";
|
||||
|
||||
export function readFile(filePath: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
fs.readFile(filePath, "utf8", (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(data);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let lineBreak = "\n";
|
||||
|
||||
/** Gets the correct line break for the current OS (git for windows will generally convert \n to \r\n during checkout) */
|
||||
export async function getLineBreak(): Promise<string> {
|
||||
const tsconfigPath = path.join("..", "tsconfig.json");
|
||||
const tsconfigFile = await readFile(tsconfigPath);
|
||||
lineBreak = _.find(["\r\n", "\n", "\r"], x => tsconfigFile.includes(x)) || "\n";
|
||||
return lineBreak;
|
||||
}
|
||||
|
||||
export function getLineNumber(fileContents: string, index: number) {
|
||||
return fileContents.substring(0, index).split(/\r\n|\n|\r/g).length + 1;
|
||||
}
|
||||
|
||||
export function tab(s: string, count: number) {
|
||||
const prepend: string = " ".repeat(count * 4);
|
||||
return (s[0] === "\n" || s[0] === "\r" ? "" : prepend) + s.replace(/(?:\r\n|\n|\r)(.)/g, `${lineBreak}${prepend}$1`);
|
||||
}
|
||||
Vendored
+3134
File diff suppressed because it is too large
Load Diff
Vendored
+117
-230
@@ -1,83 +1,77 @@
|
||||
// Type definitions for Lowdb 1.0.0
|
||||
// Type definitions for Lowdb 1.0
|
||||
// Project: https://github.com/typicode/lowdb
|
||||
// Definitions by: typicode <https://github.com/typicode>
|
||||
// Bazyli Brzóska <https://github.com/niieani>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
import { LoDashExplicitWrapper, LoDashStatic } from "lodash";
|
||||
/// <reference path="./_lodash.d.ts" />
|
||||
|
||||
import { LoDashStatic } from "lodash";
|
||||
|
||||
declare let Lowdb: Lowdb.lowdb;
|
||||
export = Lowdb;
|
||||
|
||||
declare namespace Lowdb {
|
||||
export type AdapterOptions<SchemaT extends {} = any> = {
|
||||
interface AdapterOptions<SchemaT = any> {
|
||||
defaultValue?: SchemaT;
|
||||
serialize?: (data: SchemaT) => string;
|
||||
deserialize?: (serializedData: string) => SchemaT;
|
||||
};
|
||||
}
|
||||
|
||||
export interface BaseAdapter<SchemaT extends Object = any>
|
||||
extends AdapterOptions<SchemaT> {
|
||||
interface BaseAdapter<SchemaT = any> extends AdapterOptions<SchemaT> {
|
||||
readonly "@@reference": SchemaT;
|
||||
new <SchemaT extends {} = any>(
|
||||
new <SchemaT = any>(
|
||||
source: string,
|
||||
options?: AdapterOptions<SchemaT>
|
||||
): BaseAdapter<SchemaT>;
|
||||
source: string;
|
||||
}
|
||||
|
||||
export interface AdapterSync<SchemaT extends {} = any>
|
||||
extends BaseAdapter<SchemaT> {
|
||||
new <SchemaT extends {} = any>(
|
||||
interface AdapterSync<SchemaT = any> extends BaseAdapter<SchemaT> {
|
||||
new <SchemaT = any>(
|
||||
source: string,
|
||||
options?: AdapterOptions<SchemaT>
|
||||
): AdapterSync<SchemaT>;
|
||||
readonly "@@isAsync": False;
|
||||
write(state: Object): void;
|
||||
write(state: object): void;
|
||||
}
|
||||
|
||||
export interface AdapterAsync<SchemaT extends {} = any>
|
||||
extends BaseAdapter<SchemaT> {
|
||||
new <SchemaT extends {} = any>(
|
||||
interface AdapterAsync<SchemaT = any> extends BaseAdapter<SchemaT> {
|
||||
new <SchemaT = any>(
|
||||
source: string,
|
||||
options?: AdapterOptions<SchemaT>
|
||||
): AdapterAsync<SchemaT>;
|
||||
readonly "@@isAsync": True;
|
||||
write(state: Object): Promise<void>;
|
||||
write(state: object): Promise<void>;
|
||||
}
|
||||
|
||||
export type Adapter<SchemaT extends {} = any> =
|
||||
| AdapterSync<SchemaT>
|
||||
| AdapterAsync<SchemaT>;
|
||||
|
||||
export interface LowdbBase<
|
||||
SchemaT extends {},
|
||||
AdapterT extends Adapter<SchemaT>
|
||||
> {
|
||||
read: () => Wrapper<this, AdapterT>;
|
||||
interface LowdbBase<SchemaT> {
|
||||
getState: () => SchemaT;
|
||||
setState: (state: SchemaT) => this;
|
||||
}
|
||||
|
||||
export interface Lowdb<SchemaT extends {}, AdapterT extends Adapter<SchemaT>>
|
||||
extends LowdbBase<SchemaT, AdapterT>,
|
||||
LoDashExplicitWrapper<SchemaT> {
|
||||
interface LowdbSync<SchemaT> extends LowdbBase<SchemaT>, LoDashExplicitSyncWrapper<SchemaT> {
|
||||
_: LoDashStatic;
|
||||
read: () => this;
|
||||
/**
|
||||
* @description Be careful: This function overwrites the whole database.
|
||||
*/
|
||||
write<T = void>(returnValue?: T): Wrapper<T, AdapterT>;
|
||||
write<T = void>(returnValue?: T): T;
|
||||
}
|
||||
|
||||
export interface LowdbFp<
|
||||
SchemaT extends {} = any,
|
||||
AdapterT extends Adapter<SchemaT> = Adapter<SchemaT>
|
||||
> extends LowdbBase<SchemaT, AdapterT> {
|
||||
interface LowdbAsync<SchemaT> extends LowdbBase<SchemaT>, LoDashExplicitAsyncWrapper<SchemaT> {
|
||||
_: LoDashStatic;
|
||||
read: () => Promise<this>;
|
||||
/**
|
||||
* @description Be careful: This function overwrites the whole database.
|
||||
*/
|
||||
write<T = void>(returnValue?: T): Wrapper<T, AdapterT>;
|
||||
write<T = void>(returnValue?: T): Promise<T>;
|
||||
}
|
||||
|
||||
interface LowdbFpSync<SchemaT> extends LowdbBase<SchemaT> {
|
||||
/**
|
||||
* @description Be careful: This function overwrites the whole database.
|
||||
*/
|
||||
write<T = void>(returnValue?: T): T;
|
||||
/**
|
||||
* @description Returns a function that allows you to access/modify the database at a given path.
|
||||
* @example
|
||||
@@ -90,11 +84,11 @@ declare namespace Lowdb {
|
||||
<TKey extends keyof SchemaT>(
|
||||
path: TKey | [TKey],
|
||||
defaultValue?: SchemaT[TKey]
|
||||
): FpReturn<SchemaT[TKey], AdapterT>;
|
||||
): FpReturnSync<SchemaT[TKey]>;
|
||||
<TKey extends keyof SchemaT, TSubKey extends keyof SchemaT[TKey]>(
|
||||
path: [TKey, TSubKey],
|
||||
defaultValue?: SchemaT[TKey][TSubKey]
|
||||
): FpReturn<SchemaT[TKey][TSubKey], AdapterT>;
|
||||
): FpReturnSync<SchemaT[TKey][TSubKey]>;
|
||||
<
|
||||
TKey extends keyof SchemaT,
|
||||
TSubKey extends keyof SchemaT[TKey],
|
||||
@@ -102,7 +96,7 @@ declare namespace Lowdb {
|
||||
>(
|
||||
path: [TKey, TSubKey, TSubKey2],
|
||||
defaultValue?: SchemaT[TKey][TSubKey][TSubKey2]
|
||||
): FpReturn<SchemaT[TKey][TSubKey][TSubKey2], AdapterT>;
|
||||
): FpReturnSync<SchemaT[TKey][TSubKey][TSubKey2]>;
|
||||
<
|
||||
TKey extends keyof SchemaT,
|
||||
TSubKey extends keyof SchemaT[TKey],
|
||||
@@ -111,7 +105,7 @@ declare namespace Lowdb {
|
||||
>(
|
||||
path: [TKey, TSubKey, TSubKey2, TSubKey3],
|
||||
defaultValue?: SchemaT[TKey][TSubKey][TSubKey2][TSubKey3]
|
||||
): FpReturn<SchemaT[TKey][TSubKey][TSubKey2][TSubKey3], AdapterT>;
|
||||
): FpReturnSync<SchemaT[TKey][TSubKey][TSubKey2][TSubKey3]>;
|
||||
<
|
||||
TKey extends keyof SchemaT,
|
||||
TSubKey extends keyof SchemaT[TKey],
|
||||
@@ -121,10 +115,63 @@ declare namespace Lowdb {
|
||||
>(
|
||||
path: [TKey, TSubKey, TSubKey2, TSubKey3, TSubKey4],
|
||||
defaultValue?: SchemaT[TKey][TSubKey][TSubKey2][TSubKey3][TSubKey4]
|
||||
): FpReturn<SchemaT[TKey][TSubKey][TSubKey2][TSubKey3][TSubKey4], AdapterT>;
|
||||
<T = any>(path: string | Array<string>, defaultValue?: T): T;
|
||||
): FpReturnSync<SchemaT[TKey][TSubKey][TSubKey2][TSubKey3][TSubKey4]>;
|
||||
<T = any>(path: string | string[], defaultValue?: T): FpReturnSync<T>;
|
||||
}
|
||||
export interface FpReturn<PathT, AdapterT extends Adapter> {
|
||||
|
||||
interface LowdbFpAsync<SchemaT> extends LowdbBase<SchemaT> {
|
||||
/**
|
||||
* @description Be careful: This function overwrites the whole database.
|
||||
*/
|
||||
write<T = void>(returnValue?: T): Promise<T>;
|
||||
/**
|
||||
* @description Returns a function that allows you to access/modify the database at a given path.
|
||||
* @example
|
||||
* ```js
|
||||
* const posts = db('posts')
|
||||
* const firstPost = posts(all => all[0])
|
||||
* posts.write((allPosts) => [...allPosts, {title: 'Yup!'}])
|
||||
* ```
|
||||
*/
|
||||
<TKey extends keyof SchemaT>(
|
||||
path: TKey | [TKey],
|
||||
defaultValue?: SchemaT[TKey]
|
||||
): FpReturnAsync<SchemaT[TKey]>;
|
||||
<TKey extends keyof SchemaT, TSubKey extends keyof SchemaT[TKey]>(
|
||||
path: [TKey, TSubKey],
|
||||
defaultValue?: SchemaT[TKey][TSubKey]
|
||||
): FpReturnAsync<SchemaT[TKey][TSubKey]>;
|
||||
<
|
||||
TKey extends keyof SchemaT,
|
||||
TSubKey extends keyof SchemaT[TKey],
|
||||
TSubKey2 extends keyof SchemaT[TKey][TSubKey]
|
||||
>(
|
||||
path: [TKey, TSubKey, TSubKey2],
|
||||
defaultValue?: SchemaT[TKey][TSubKey][TSubKey2]
|
||||
): FpReturnAsync<SchemaT[TKey][TSubKey][TSubKey2]>;
|
||||
<
|
||||
TKey extends keyof SchemaT,
|
||||
TSubKey extends keyof SchemaT[TKey],
|
||||
TSubKey2 extends keyof SchemaT[TKey][TSubKey],
|
||||
TSubKey3 extends keyof SchemaT[TKey][TSubKey][TSubKey2]
|
||||
>(
|
||||
path: [TKey, TSubKey, TSubKey2, TSubKey3],
|
||||
defaultValue?: SchemaT[TKey][TSubKey][TSubKey2][TSubKey3]
|
||||
): FpReturnAsync<SchemaT[TKey][TSubKey][TSubKey2][TSubKey3]>;
|
||||
<
|
||||
TKey extends keyof SchemaT,
|
||||
TSubKey extends keyof SchemaT[TKey],
|
||||
TSubKey2 extends keyof SchemaT[TKey][TSubKey],
|
||||
TSubKey3 extends keyof SchemaT[TKey][TSubKey][TSubKey2],
|
||||
TSubKey4 extends keyof SchemaT[TKey][TSubKey][TSubKey2][TSubKey3]
|
||||
>(
|
||||
path: [TKey, TSubKey, TSubKey2, TSubKey3, TSubKey4],
|
||||
defaultValue?: SchemaT[TKey][TSubKey][TSubKey2][TSubKey3][TSubKey4]
|
||||
): FpReturnAsync<SchemaT[TKey][TSubKey][TSubKey2][TSubKey3][TSubKey4]>;
|
||||
<T = any>(path: string | string[], defaultValue?: T): FpReturnAsync<T>;
|
||||
}
|
||||
|
||||
interface FpReturnBase<PathT> {
|
||||
/**
|
||||
* Execute a series of functions on the data at a given path.
|
||||
* Result of previous function is the input of the next one.
|
||||
@@ -168,7 +215,8 @@ declare namespace Lowdb {
|
||||
]
|
||||
): R7;
|
||||
(funcs: Array<(a: any) => any>): any;
|
||||
|
||||
}
|
||||
interface FpReturnSync<PathT> extends FpReturnBase<PathT> {
|
||||
/**
|
||||
* @description Writes the change to the database, based on the callback's return value.
|
||||
* @example
|
||||
@@ -176,198 +224,37 @@ declare namespace Lowdb {
|
||||
* posts.write((allPosts) => [...allPosts, {title: 'Yup!'}])
|
||||
* ```
|
||||
*/
|
||||
write<R1 extends PathT>(f1: (a1: PathT) => R1): Wrapper<R1, AdapterT>;
|
||||
write<R1 extends PathT>(f1: (a1: PathT) => R1): R1;
|
||||
}
|
||||
interface FpReturnAsync<PathT> extends FpReturnBase<PathT> {
|
||||
/**
|
||||
* @description Writes the change to the database, based on the callback's return value.
|
||||
* @example
|
||||
* ```js
|
||||
* posts.write((allPosts) => [...allPosts, {title: 'Yup!'}])
|
||||
* ```
|
||||
*/
|
||||
write<R1 extends PathT>(f1: (a1: PathT) => R1): Promise<R1>;
|
||||
}
|
||||
|
||||
export type lowdb = <
|
||||
SchemaT extends AdapterT[ReferenceProperty],
|
||||
AdapterT extends Adapter
|
||||
>(
|
||||
adapter: AdapterT
|
||||
) => If<
|
||||
AdapterT[AsyncProperty],
|
||||
Promise<Lowdb<RecursivelyExtend<SchemaT, AsyncTag>, AdapterT>>,
|
||||
Lowdb<RecursivelyExtend<SchemaT, SyncTag>, AdapterT>
|
||||
>;
|
||||
interface lowdb {
|
||||
<AdapterT extends AdapterAsync>(adapter: AdapterT): Promise<LowdbAsync<AdapterT[ReferenceProperty]>>;
|
||||
<AdapterT extends AdapterSync>(adapter: AdapterT): LowdbSync<AdapterT[ReferenceProperty]>;
|
||||
}
|
||||
|
||||
export type lowdbFp = <
|
||||
SchemaT extends AdapterT[ReferenceProperty],
|
||||
AdapterT extends Adapter
|
||||
>(
|
||||
adapter: AdapterT
|
||||
) => If<
|
||||
AdapterT[AsyncProperty],
|
||||
Promise<LowdbFp<SchemaT & AsyncTag, AdapterT>>,
|
||||
LowdbFp<SchemaT & SyncTag, AdapterT>
|
||||
>;
|
||||
interface lowdbFp {
|
||||
<AdapterT extends AdapterAsync>(adapter: AdapterT): Promise<LowdbFpAsync<AdapterT[ReferenceProperty]>>;
|
||||
<AdapterT extends AdapterSync>(adapter: AdapterT): LowdbFpSync<AdapterT[ReferenceProperty]>;
|
||||
}
|
||||
|
||||
export type Wrapper<T, AdapterT extends Adapter> = WrapInPromiseIfTrue<
|
||||
T,
|
||||
AdapterT[AsyncProperty]
|
||||
>;
|
||||
}
|
||||
|
||||
/**
|
||||
* lodash augmentation is necessary in order not to duplicate the whole lodash definition
|
||||
* it's mostly harmless, aside from the fact that 'write' becomes a method in a lodash.chain()
|
||||
*/
|
||||
declare module "lodash" {
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
write(): WrapInPromiseIfAsyncTag<TValue, GetReferenceTypeIfDefined<TValue>>;
|
||||
// override lodash's methods only if source tag is present:
|
||||
value(): GetReferenceTypeIfDefined<TValue>;
|
||||
// Note: this interface is augmented in _lodash.d.ts
|
||||
interface LoDashExplicitSyncWrapper<TValue> extends _.LoDashWrapper<TValue> {
|
||||
write(): TValue;
|
||||
}
|
||||
// Note: this interface is augmented in _lodash.d.ts
|
||||
interface LoDashExplicitAsyncWrapper<TValue> extends _.LoDashWrapper<TValue> {
|
||||
write(): Promise<TValue>;
|
||||
}
|
||||
}
|
||||
|
||||
// utility types:
|
||||
type WrapInPromiseIfTrue<T, IsAsync extends Bool> = If<IsAsync, Promise<T>, T>;
|
||||
type ReferenceProperty = "@@reference";
|
||||
/**
|
||||
* Hidden source property for resolving to the correct type.
|
||||
* It is doubly nested so that we retain all nullability information
|
||||
*/
|
||||
type SourceReference<T> = {
|
||||
readonly "@@reference"?: { readonly "@@reference": T };
|
||||
};
|
||||
type GetReferenceParent<T, U = NonNull<T>> = NonNull<
|
||||
U[keyof U & ReferenceProperty]
|
||||
>;
|
||||
type GetDefinedReferenceType<
|
||||
TValue,
|
||||
SourceParent = GetReferenceParent<TValue>
|
||||
> = SourceParent[keyof SourceParent & ReferenceProperty];
|
||||
type AsyncProperty = "@@isAsync";
|
||||
type AsyncTag = { readonly "@@reference"?: { readonly "@@isAsync"?: true } };
|
||||
type SyncTag = {};
|
||||
type HasAsyncTag<TaggedT, ReferenceT = GetReferenceParent<TaggedT>> = If<
|
||||
HasReferenceProperty<TaggedT>,
|
||||
UnionHasKey<keyof ReferenceT, AsyncProperty>,
|
||||
False
|
||||
>;
|
||||
type HasReferenceProperty<T> = UnionHasKey<keyof NonNull<T>, ReferenceProperty>;
|
||||
type WrapInPromiseIfAsyncTag<
|
||||
TaggedT,
|
||||
WrappedT = GetReferenceTypeIfDefined<TaggedT>
|
||||
> = WrapInPromiseIfTrue<WrappedT, HasAsyncTag<TaggedT>>;
|
||||
|
||||
/**
|
||||
* Resolves the hidden source type
|
||||
* while preserving nullability as much as possible
|
||||
*/
|
||||
type GetReferenceType<TValue, Source = GetDefinedReferenceType<TValue>> = If<
|
||||
IsEmptyType<TValue>,
|
||||
Source | undefined,
|
||||
Source
|
||||
>;
|
||||
|
||||
type GetReferenceTypeIfDefined<T> = If<
|
||||
HasReferenceProperty<T>,
|
||||
GetReferenceType<T>,
|
||||
T
|
||||
>;
|
||||
|
||||
type RecursivelyExtend<T, AddT> = If<
|
||||
IsArrayType<T>,
|
||||
MapArrayType<T & List<{}>, AddT>,
|
||||
MapScalarOrObjectType<T, AddT>
|
||||
> &
|
||||
SourceReference<T>;
|
||||
|
||||
type MapScalarOrObjectType<T, AddT> = If<
|
||||
IsScalarOrInstance<T>,
|
||||
T,
|
||||
MapObjectWithPossibleArrays<T, AddT> & SourceReference<T> & AddT
|
||||
>;
|
||||
|
||||
type MapObjectWithPossibleArrays<T, AddT> = {
|
||||
[P in keyof T]: If<
|
||||
IsArrayType<T[P]>,
|
||||
MapArrayType<T[P] & List<{}>, AddT> & SourceReference<T[P]>,
|
||||
MapScalarOrObjectType<T[P], AddT>
|
||||
>
|
||||
};
|
||||
|
||||
type MapArrayType<Arr extends List<T>, AddT, T = Arr[-1]> = Array<
|
||||
MapObjectWithPossibleArrays<T, AddT> & SourceReference<T> & AddT
|
||||
> &
|
||||
AddT;
|
||||
|
||||
//////////////////////////////////////////
|
||||
// generic utils (some from https://github.com/tycho01/typical/):
|
||||
|
||||
type False = "0";
|
||||
type True = "1";
|
||||
type Bool = True | False;
|
||||
type If<Cond extends Bool, Then, Else> = { 1: Then; 0: Else }[Cond];
|
||||
|
||||
type Obj<T> = { [k: string]: T };
|
||||
|
||||
type And<A extends Bool, B extends Bool> = ({ 1: { 1: "1" } & Obj<"0"> } & Obj<
|
||||
Obj<"0">
|
||||
>)[A][B];
|
||||
|
||||
type UnionHasKey<Union extends string, K extends string> = ({
|
||||
[S in Union]: "1"
|
||||
} &
|
||||
Obj<"0">)[K];
|
||||
|
||||
type Indeterminate<T extends string> = And<
|
||||
UnionHasKey<T, "0">,
|
||||
UnionHasKey<T, "1">
|
||||
>;
|
||||
|
||||
type Not<T extends Bool> = { "1": "0"; "0": "1" }[T];
|
||||
|
||||
type Determinate<T extends Bool> = Not<Indeterminate<T>>;
|
||||
|
||||
type DefinitelyYes<T extends Bool> = And<T, Determinate<T>>;
|
||||
|
||||
type UnionContained<T extends string, U extends string> = DefinitelyYes<
|
||||
({ [P in U]: "1" } & Obj<"0">)[T | U]
|
||||
>;
|
||||
|
||||
type UnionEmpty<T extends string> = And<
|
||||
UnionContained<T, "foo">,
|
||||
UnionContained<T, "bar">
|
||||
>;
|
||||
|
||||
type UnionToObject<Keys extends string> = { [K in Keys]: K };
|
||||
|
||||
type Keyed<T> = { [K in keyof T]: K };
|
||||
|
||||
type KeyedSafe<T> = Keyed<T> & Obj<never>;
|
||||
|
||||
type IntersectionUnions<Big extends string, Small extends string> = KeyedSafe<
|
||||
UnionToObject<Small>
|
||||
>[Big];
|
||||
type UnionsOverlap<Big extends string, Small extends string> = Not<
|
||||
UnionEmpty<IntersectionUnions<Big, Small>>
|
||||
>;
|
||||
|
||||
type DiffUnion<T extends string, U extends string> = ({ [P in T]: P } &
|
||||
{ [P in U]: never } & { [k: string]: never })[T];
|
||||
|
||||
type ObjectHasKey<O extends {}, K extends string> = UnionHasKey<keyof O, K>;
|
||||
|
||||
type ArrayPrototypeProperties = DiffUnion<
|
||||
keyof Array<any>,
|
||||
"toString" | "toLocaleString"
|
||||
>;
|
||||
type IsArrayType<T> = DefinitelyYes<ObjectHasKey<T, ArrayPrototypeProperties>>;
|
||||
/**
|
||||
* either: undefined, never, null or {}
|
||||
* can also be used to check if one union contains one of the above
|
||||
**/
|
||||
type IsEmptyType<T> = UnionEmpty<keyof T>;
|
||||
|
||||
/**
|
||||
* false for: undefined, interfaces
|
||||
* true for: Array, boolean, number, string, Object
|
||||
*/
|
||||
type IsScalarOrInstance<T> = ObjectHasKeySafe<T, "valueOf">;
|
||||
type ObjectHasKeySafe<O, K extends string> = UnionsOverlap<keyof O, K>;
|
||||
type NonNull<T> = T & {};
|
||||
|
||||
interface List<T> {
|
||||
readonly [n: number]: T;
|
||||
}
|
||||
|
||||
+27
-46
@@ -1,12 +1,14 @@
|
||||
import * as low from "lowdb";
|
||||
import * as lowfp from "lowdb/lib/fp";
|
||||
import * as Base from "lowdb/adapters/Base";
|
||||
import * as FileSync from "lowdb/adapters/FileSync";
|
||||
import * as FileAsync from "lowdb/adapters/FileAsync";
|
||||
import * as LocalStorage from "lowdb/adapters/LocalStorage";
|
||||
import { find, filter, random, concat, sortBy, take, set } from "lodash/fp";
|
||||
|
||||
const adapterSync: low.AdapterSync<{}> = new FileSync("db.json");
|
||||
const adapterAsync: low.AdapterAsync<{}> = new FileAsync("db.json");
|
||||
const db = low<DbSchema, typeof adapterSync>(adapterSync);
|
||||
const adapterSync = new FileSync<DbSchema>("db.json");
|
||||
const adapterAsync = new FileAsync<DbSchema>("db.json");
|
||||
const db = low(adapterSync);
|
||||
|
||||
const write: DbSchema = db.defaults({ posts: [] }).write();
|
||||
|
||||
@@ -15,25 +17,16 @@ const result: Post[] = db
|
||||
.push({ title: "hello", views: 123 })
|
||||
.value();
|
||||
|
||||
const teste = db.get("user").value();
|
||||
const post: Post | undefined = db
|
||||
.get("posts")
|
||||
// $ExpectType Post | undefined
|
||||
db.get("posts")
|
||||
.find({ id: 123 })
|
||||
.value();
|
||||
|
||||
// $ExpectError
|
||||
const postAssertWithUndefined: Post = db
|
||||
.get("posts")
|
||||
.find({ id: 123 })
|
||||
.value();
|
||||
|
||||
// $ExpectError
|
||||
const postAssertWithUndefined2: Post = db
|
||||
.get("posts")
|
||||
// $ExpectType Post | undefined
|
||||
db.get("posts")
|
||||
.find({ id: 123 })
|
||||
.write();
|
||||
|
||||
low<DbSchema, typeof adapterAsync>(adapterAsync).then(dbAsync => {
|
||||
low(adapterAsync).then(dbAsync => {
|
||||
const writeAction: Promise<Post> = dbAsync
|
||||
.get("posts")
|
||||
.push({ title: "async hello" })
|
||||
@@ -76,11 +69,10 @@ async () => {
|
||||
|
||||
const dbSync = low(adapterSync);
|
||||
const dbAsync = await low(adapterAsync);
|
||||
const dbAssertTypeSync: low.Lowdb<ExampleSchema, typeof adapterSync> = dbSync;
|
||||
const dbAssertTypeAsync: low.Lowdb<
|
||||
ExampleSchema,
|
||||
typeof adapterAsync
|
||||
> = dbAsync;
|
||||
// $ExpectType LowdbSync<ExampleSchema>
|
||||
dbSync;
|
||||
// $ExpectType LowdbAsync<ExampleSchema>
|
||||
dbAsync;
|
||||
|
||||
const xSync: ExampleSchema = dbSync
|
||||
.defaults({ posts: [{ name: "baz" }] })
|
||||
@@ -100,7 +92,9 @@ async () => {
|
||||
.push({ name: "hello" })
|
||||
.write();
|
||||
|
||||
const dbPromise = low<OtherSchema, typeof adapterAsync>(adapterAsync);
|
||||
const otherAdapterAsync = new FileAsync<OtherSchema>("db.json");
|
||||
|
||||
const dbPromise = low(otherAdapterAsync);
|
||||
const db = await dbPromise;
|
||||
|
||||
const nested: OtherSchema["nested"] = db.get("nested").value();
|
||||
@@ -124,37 +118,32 @@ const weDidNotBreakLodash: ExampleSchema["posts"] = lodashChain
|
||||
const adapterLS = new LocalStorage<DbSchema>("test.json");
|
||||
const dbFP = lowfp(adapterLS);
|
||||
// Get posts
|
||||
const postsFP: low.FpReturn<Post[], low.AdapterSync<DbSchema>> = dbFP(
|
||||
"posts"
|
||||
);
|
||||
const postsFP = dbFP("posts");
|
||||
|
||||
// replace posts with a new array resulting from concat
|
||||
// and persist database
|
||||
const write: Post[] = postsFP.write(
|
||||
concat({ title: "lowdb is awesome", views: random(0, 5) })
|
||||
concat<Post>({ title: "lowdb is awesome", views: random(0, 5) })
|
||||
);
|
||||
|
||||
// Find post by id
|
||||
const post: Post = postsFP(find({ id: 1 }));
|
||||
const post: Post | undefined = postsFP(find<Post>({ id: 1 }));
|
||||
|
||||
// Find top 5 fives posts
|
||||
const popular: Post[] = postsFP([
|
||||
sortBy("views") as PostsAction,
|
||||
sortBy<Post>("views") as PostsAction,
|
||||
take(5) as PostsAction
|
||||
]);
|
||||
|
||||
const filtered: Post[] = dbFP("posts")(filter({ published: true }));
|
||||
const writeAction: Post[] = dbFP("posts").write(concat({ id: "123" }));
|
||||
const writeAction2: string = dbFP(["user", "name"]).write(set("typicode"));
|
||||
const filtered: Post[] = dbFP("posts")(filter<Post>({ published: true }));
|
||||
const writeAction: Post[] = dbFP("posts").write(concat<Post>({ id: 123 }));
|
||||
const writeAction2: string = dbFP(["user", "name"]).write(() => "typicode");
|
||||
|
||||
async () => {
|
||||
const adapterAsync = new FileAsync<DbSchema>("test.json");
|
||||
const dbAsyncPromise = lowfp(adapterAsync);
|
||||
const dbAsync = await dbAsyncPromise;
|
||||
const postsWithDefault: low.FpReturn<
|
||||
Post[],
|
||||
low.AdapterAsync<DbSchema>
|
||||
> = dbAsync("posts", [{ title: "baz" }] as Post[]);
|
||||
const postsWithDefault = dbAsync("posts", [{ title: "baz" }] as Post[]);
|
||||
|
||||
const func: Promise<Post[]> = postsWithDefault.write(post => [
|
||||
...post,
|
||||
@@ -165,16 +154,8 @@ const weDidNotBreakLodash: ExampleSchema["posts"] = lodashChain
|
||||
type PostsAction = (posts: Post[]) => Post[];
|
||||
};
|
||||
|
||||
declare function find<A, B extends A>(a: B): (arr: A[]) => A;
|
||||
declare function filter<A, B extends A>(a: B): (arr: A[]) => A[];
|
||||
declare function random(a: number, b: number): number;
|
||||
declare function concat(a: any): <A>(arr: A) => A;
|
||||
declare function sortBy(a: any): <A>(arr: A) => A;
|
||||
declare function take<A>(a: A): <A>(arr: A) => A;
|
||||
declare function set<A>(a: A): (val: A) => A;
|
||||
|
||||
interface DbSchema {
|
||||
posts: Array<Post>;
|
||||
posts: Post[];
|
||||
user: {
|
||||
name: string;
|
||||
};
|
||||
@@ -184,7 +165,7 @@ interface Post {
|
||||
title?: string;
|
||||
views?: number;
|
||||
id?: number;
|
||||
published?: boolean | undefined;
|
||||
published?: boolean;
|
||||
tuple?: [boolean, number];
|
||||
}
|
||||
|
||||
|
||||
+1
-74
@@ -1,79 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
"no-misused-new": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user