mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
lodash: fix pickBy for dictionary types (#27131)
Fixes #24133 (I know it's closed but as per the discussion there, it wasn't fixed properly before). Please fill in this template. - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). If changing an existing definition: - [ ] Provide a URL to documentation or source code which provides context for the suggested changes: N/A - [ ] Increase the version number in the header if appropriate. N/A - [x] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.
This commit is contained in:
committed by
Ryan Cavanaugh
parent
8815592a2a
commit
e3ff16475b
Vendored
+96
@@ -2951,6 +2951,22 @@ declare module "../index" {
|
||||
* _.omitBy(object, _.isNumber);
|
||||
* // => { 'b': '2' }
|
||||
*/
|
||||
omitBy<T>(
|
||||
object: Dictionary<T> | null | undefined,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
omitBy<T>(
|
||||
object: NumericDictionary<T> | null | undefined,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): NumericDictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
omitBy<T extends object>(
|
||||
object: T | null | undefined,
|
||||
predicate: ValueKeyIteratee<T[keyof T]>
|
||||
@@ -2958,6 +2974,22 @@ declare module "../index" {
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
omitBy<T>(
|
||||
this: LoDashImplicitWrapper<Dictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashImplicitWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
omitBy<T>(
|
||||
this: LoDashImplicitWrapper<NumericDictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashImplicitWrapper<NumericDictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
@@ -2968,6 +3000,22 @@ declare module "../index" {
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
omitBy<T>(
|
||||
this: LoDashExplicitWrapper<Dictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashExplicitWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
omitBy<T>(
|
||||
this: LoDashExplicitWrapper<NumericDictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashExplicitWrapper<NumericDictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.omitBy
|
||||
*/
|
||||
@@ -3063,6 +3111,22 @@ declare module "../index" {
|
||||
* _.pickBy(object, _.isNumber);
|
||||
* // => { 'a': 1, 'c': 3 }
|
||||
*/
|
||||
pickBy<T>(
|
||||
object: Dictionary<T> | null | undefined,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
pickBy<T>(
|
||||
object: NumericDictionary<T> | null | undefined,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): NumericDictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
pickBy<T extends object>(
|
||||
object: T | null | undefined,
|
||||
predicate?: ValueKeyIteratee<T[keyof T]>
|
||||
@@ -3070,6 +3134,22 @@ declare module "../index" {
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
pickBy<T>(
|
||||
this: LoDashImplicitWrapper<Dictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashImplicitWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
pickBy<T>(
|
||||
this: LoDashImplicitWrapper<NumericDictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashImplicitWrapper<NumericDictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
@@ -3080,6 +3160,22 @@ declare module "../index" {
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<TValue> {
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
pickBy<T>(
|
||||
this: LoDashExplicitWrapper<Dictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashExplicitWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
pickBy<T>(
|
||||
this: LoDashExplicitWrapper<NumericDictionary<T> | null | undefined>,
|
||||
predicate?: ValueKeyIteratee<T>
|
||||
): LoDashExplicitWrapper<NumericDictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.pickBy
|
||||
*/
|
||||
|
||||
Vendored
+26
-6
@@ -2289,11 +2289,21 @@ declare namespace _ {
|
||||
}
|
||||
interface LodashOmitBy {
|
||||
<T>(predicate: lodash.ValueKeyIteratee<T>): LodashOmitBy1x1<T>;
|
||||
<T extends object>(predicate: lodash.__, object: T | null | undefined): LodashOmitBy1x2<T>;
|
||||
<T>(predicate: lodash.__, object: lodash.Dictionary<T> | null | undefined): LodashOmitBy1x2<T>;
|
||||
<T>(predicate: lodash.ValueKeyIteratee<T>, object: lodash.Dictionary<T> | null | undefined): lodash.Dictionary<T>;
|
||||
<T>(predicate: lodash.__, object: lodash.NumericDictionary<T> | null | undefined): LodashOmitBy2x2<T>;
|
||||
<T>(predicate: lodash.ValueKeyIteratee<T>, object: lodash.NumericDictionary<T> | null | undefined): lodash.NumericDictionary<T>;
|
||||
<T extends object>(predicate: lodash.__, object: T | null | undefined): LodashOmitBy3x2<T>;
|
||||
<T extends object>(predicate: lodash.ValueKeyIteratee<T[keyof T]>, object: T | null | undefined): lodash.PartialObject<T>;
|
||||
}
|
||||
type LodashOmitBy1x1<T> = <T1 extends object>(object: T1 | null | undefined) => lodash.PartialObject<T1>;
|
||||
type LodashOmitBy1x2<T> = (predicate: lodash.ValueKeyIteratee<T[keyof T]>) => lodash.PartialObject<T>;
|
||||
interface LodashOmitBy1x1<T> {
|
||||
(object: lodash.Dictionary<T> | null | undefined): lodash.Dictionary<T>;
|
||||
(object: lodash.NumericDictionary<T> | null | undefined): lodash.NumericDictionary<T>;
|
||||
<T1 extends object>(object: T1 | null | undefined): lodash.PartialObject<T1>;
|
||||
}
|
||||
type LodashOmitBy1x2<T> = (predicate: lodash.ValueKeyIteratee<T>) => lodash.Dictionary<T>;
|
||||
type LodashOmitBy2x2<T> = (predicate: lodash.ValueKeyIteratee<T>) => lodash.NumericDictionary<T>;
|
||||
type LodashOmitBy3x2<T> = (predicate: lodash.ValueKeyIteratee<T[keyof T]>) => lodash.PartialObject<T>;
|
||||
type LodashOnce = <T extends (...args: any[]) => any>(func: T) => T;
|
||||
interface LodashOrderBy {
|
||||
<T>(iteratees: lodash.Many<(value: T) => lodash.NotVoid>): LodashOrderBy1x1<T>;
|
||||
@@ -2873,11 +2883,21 @@ declare namespace _ {
|
||||
type LodashPick2x2<T> = (props: lodash.PropertyPath) => lodash.PartialDeep<T>;
|
||||
interface LodashPickBy {
|
||||
<T>(predicate: lodash.ValueKeyIteratee<T>): LodashPickBy1x1<T>;
|
||||
<T extends object>(predicate: lodash.__, object: T | null | undefined): LodashPickBy1x2<T>;
|
||||
<T>(predicate: lodash.__, object: lodash.Dictionary<T> | null | undefined): LodashPickBy1x2<T>;
|
||||
<T>(predicate: lodash.ValueKeyIteratee<T>, object: lodash.Dictionary<T> | null | undefined): lodash.Dictionary<T>;
|
||||
<T>(predicate: lodash.__, object: lodash.NumericDictionary<T> | null | undefined): LodashPickBy2x2<T>;
|
||||
<T>(predicate: lodash.ValueKeyIteratee<T>, object: lodash.NumericDictionary<T> | null | undefined): lodash.NumericDictionary<T>;
|
||||
<T extends object>(predicate: lodash.__, object: T | null | undefined): LodashPickBy3x2<T>;
|
||||
<T extends object>(predicate: lodash.ValueKeyIteratee<T[keyof T]>, object: T | null | undefined): lodash.PartialObject<T>;
|
||||
}
|
||||
type LodashPickBy1x1<T> = <T1 extends object>(object: T1 | null | undefined) => lodash.PartialObject<T1>;
|
||||
type LodashPickBy1x2<T> = (predicate: lodash.ValueKeyIteratee<T[keyof T]>) => lodash.PartialObject<T>;
|
||||
interface LodashPickBy1x1<T> {
|
||||
(object: lodash.Dictionary<T> | null | undefined): lodash.Dictionary<T>;
|
||||
(object: lodash.NumericDictionary<T> | null | undefined): lodash.NumericDictionary<T>;
|
||||
<T1 extends object>(object: T1 | null | undefined): lodash.PartialObject<T1>;
|
||||
}
|
||||
type LodashPickBy1x2<T> = (predicate: lodash.ValueKeyIteratee<T>) => lodash.Dictionary<T>;
|
||||
type LodashPickBy2x2<T> = (predicate: lodash.ValueKeyIteratee<T>) => lodash.NumericDictionary<T>;
|
||||
type LodashPickBy3x2<T> = (predicate: lodash.ValueKeyIteratee<T[keyof T]>) => lodash.PartialObject<T>;
|
||||
interface LodashProp {
|
||||
<TObject extends object, TKey extends keyof TObject>(path: TKey | [TKey]): LodashProp1x1<TObject, TKey>;
|
||||
<TObject extends object>(path: lodash.__, object: TObject): LodashProp1x2<TObject>;
|
||||
|
||||
@@ -5561,13 +5561,23 @@ fp.now(); // $ExpectType number
|
||||
// _.omitBy
|
||||
{
|
||||
const obj: AbcObject | null | undefined = anything;
|
||||
const dictionary: _.Dictionary<boolean> | null | undefined = anything;
|
||||
const numericDictionary: _.NumericDictionary<boolean> | null | undefined = anything;
|
||||
const predicate = (element: string | number | boolean, key: string) => true;
|
||||
const predicate2 = (element: boolean, key: string) => true;
|
||||
|
||||
_.omitBy(obj, predicate); // $ExpectType Partial<AbcObject>
|
||||
_.omitBy(dictionary, predicate2); // $ExpectType Dictionary<boolean>
|
||||
_.omitBy(numericDictionary, predicate2); // $ExpectType NumericDictionary<boolean>
|
||||
_(obj).omitBy(predicate); // $ExpectType LoDashImplicitWrapper<Partial<AbcObject>>
|
||||
_(dictionary).omitBy(predicate2); // $ExpectType LoDashImplicitWrapper<Dictionary<boolean>>
|
||||
_(numericDictionary).omitBy(predicate2); // $ExpectType LoDashImplicitWrapper<NumericDictionary<boolean>>
|
||||
_.chain(obj).omitBy(predicate); // $ExpectType LoDashExplicitWrapper<Partial<AbcObject>>
|
||||
_.chain(dictionary).omitBy(predicate2); // $ExpectType LoDashExplicitWrapper<Dictionary<boolean>>
|
||||
_.chain(numericDictionary).omitBy(predicate2); // $ExpectType LoDashExplicitWrapper<NumericDictionary<boolean>>
|
||||
fp.omitBy(predicate, obj); // $ExpectType Partial<AbcObject>
|
||||
fp.omitBy(predicate)(obj); // $ExpectType Partial<AbcObject>
|
||||
fp.omitBy(predicate2)(dictionary); // $ExpectType Dictionary<boolean>
|
||||
fp.omitBy(predicate2)(numericDictionary); // $ExpectType NumericDictionary<boolean>
|
||||
}
|
||||
|
||||
// _.pick
|
||||
@@ -5584,8 +5594,10 @@ fp.now(); // $ExpectType number
|
||||
_.pick(obj1, readonlyArray); // $ExpectType PartialDeep<AbcObject>
|
||||
// Broken in TS 2.4
|
||||
// _.pick(obj2, "a", "b"); // Pick<AbcObject, "a" | "b">
|
||||
_.pick(obj2, literalsArray); // $ExpectType Pick<AbcObject, "a" | "b">
|
||||
_.pick(obj2, roLiteralsArray); // $ExpectType Pick<AbcObject, "a" | "b">
|
||||
// We can't use ExpectType here because typescript keeps changing what order the types appear.
|
||||
let result1: Pick<AbcObject, "a" | "b">;
|
||||
result1 = _.pick(obj2, literalsArray);
|
||||
result1 = _.pick(obj2, roLiteralsArray);
|
||||
|
||||
_(obj1).pick("a"); // $ExpectType LoDashImplicitWrapper<Partial<AbcObject>>
|
||||
_(obj1).pick(0, "a"); // $ExpectType LoDashImplicitWrapper<Partial<AbcObject>>
|
||||
@@ -5593,8 +5605,9 @@ fp.now(); // $ExpectType number
|
||||
_(obj1).pick(readonlyArray); // $ExpectType LoDashImplicitWrapper<Partial<AbcObject>>
|
||||
// Broken in TS 2.4
|
||||
// _(obj2).pick("a", "b"); // LoDashImplicitWrapper<Pick<AbcObject, "a" | "b">>
|
||||
_(obj2).pick(literalsArray); // $ExpectType LoDashImplicitWrapper<Pick<AbcObject, "a" | "b">>
|
||||
_(obj2).pick(roLiteralsArray); // $ExpectType LoDashImplicitWrapper<Pick<AbcObject, "a" | "b">>
|
||||
let result2: _.LoDashImplicitWrapper<Pick<AbcObject, "a" | "b">>;
|
||||
result2 = _(obj2).pick(literalsArray);
|
||||
result2 = _(obj2).pick(roLiteralsArray);
|
||||
|
||||
_.chain(obj1).pick("a"); // $ExpectType LoDashExplicitWrapper<Partial<AbcObject>>
|
||||
_.chain(obj1).pick(0, "a"); // $ExpectType LoDashExplicitWrapper<Partial<AbcObject>>
|
||||
@@ -5602,24 +5615,35 @@ fp.now(); // $ExpectType number
|
||||
_.chain(obj1).pick(readonlyArray); // $ExpectType LoDashExplicitWrapper<Partial<AbcObject>>
|
||||
// Broken in TS 2.4
|
||||
// _.chain(obj2).pick("a", "b"); // LoDashExplicitWrapper<Pick<AbcObject, "a" | "b">>
|
||||
_.chain(obj2).pick(literalsArray); // $ExpectType LoDashExplicitWrapper<Pick<AbcObject, "a" | "b">>
|
||||
_.chain(obj2).pick(roLiteralsArray); // $ExpectType LoDashExplicitWrapper<Pick<AbcObject, "a" | "b">>
|
||||
let result3: _.LoDashExplicitWrapper<Pick<AbcObject, "a" | "b">>;
|
||||
result3 = _.chain(obj2).pick(literalsArray);
|
||||
result3 = _.chain(obj2).pick(roLiteralsArray);
|
||||
|
||||
fp.pick<AbcObject, "a">("a", obj2); // $ExpectType Pick<AbcObject, "a">
|
||||
fp.pick<AbcObject, "a">("a")(obj2); // $ExpectType Pick<AbcObject, "a">
|
||||
fp.pick<AbcObject, "a" | "b">(literalsArray)(obj2); // $ExpectType Pick<AbcObject, "a" | "b">
|
||||
result1 = fp.pick<AbcObject, "a" | "b">(literalsArray)(obj2);
|
||||
}
|
||||
|
||||
// _.pickBy
|
||||
{
|
||||
const obj: AbcObject | null | undefined = anything;
|
||||
const dictionary: _.Dictionary<boolean> | null | undefined = anything;
|
||||
const numericDictionary: _.NumericDictionary<boolean> | null | undefined = anything;
|
||||
const predicate = (element: string | number | boolean, key: string) => true;
|
||||
const predicate2 = (element: boolean, key: string) => true;
|
||||
|
||||
_.pickBy(obj, predicate); // $ExpectType Partial<AbcObject>
|
||||
_.pickBy(dictionary, predicate2); // $ExpectType Dictionary<boolean>
|
||||
_.pickBy(numericDictionary, predicate2); // $ExpectType NumericDictionary<boolean>
|
||||
_(obj).pickBy(predicate); // $ExpectType LoDashImplicitWrapper<Partial<AbcObject>>
|
||||
_(dictionary).pickBy(predicate2); // $ExpectType LoDashImplicitWrapper<Dictionary<boolean>>
|
||||
_(numericDictionary).pickBy(predicate2); // $ExpectType LoDashImplicitWrapper<NumericDictionary<boolean>>
|
||||
_.chain(obj).pickBy(predicate); // $ExpectType LoDashExplicitWrapper<Partial<AbcObject>>
|
||||
_.chain(dictionary).pickBy(predicate2); // $ExpectType LoDashExplicitWrapper<Dictionary<boolean>>
|
||||
_.chain(numericDictionary).pickBy(predicate2); // $ExpectType LoDashExplicitWrapper<NumericDictionary<boolean>>
|
||||
fp.pickBy(predicate, obj); // $ExpectType Partial<AbcObject>
|
||||
fp.pickBy(predicate)(obj); // $ExpectType Partial<AbcObject>
|
||||
fp.pickBy(predicate2)(dictionary); // $ExpectType Dictionary<boolean>
|
||||
fp.pickBy(predicate2)(numericDictionary); // $ExpectType NumericDictionary<boolean>
|
||||
}
|
||||
|
||||
// _.result
|
||||
|
||||
Vendored
+32
@@ -1273,6 +1273,14 @@ declare module "./index" {
|
||||
this: LoDashExplicitSyncWrapper<T | null | undefined>,
|
||||
...paths: Array<_.Many<_.PropertyName>>
|
||||
): LoDashExplicitSyncWrapper<_.PartialObject<T>>;
|
||||
omitBy<T>(
|
||||
this: LoDashExplicitSyncWrapper<_.Dictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitSyncWrapper<_.Dictionary<T>>;
|
||||
omitBy<T>(
|
||||
this: LoDashExplicitSyncWrapper<_.NumericDictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitSyncWrapper<_.NumericDictionary<T>>;
|
||||
omitBy<T extends object>(
|
||||
this: LoDashExplicitSyncWrapper<T | null | undefined>,
|
||||
predicate: _.ValueKeyIteratee<T[keyof T]>
|
||||
@@ -1285,6 +1293,14 @@ declare module "./index" {
|
||||
this: LoDashExplicitSyncWrapper<T | null | undefined>,
|
||||
...props: _.PropertyPath[]
|
||||
): LoDashExplicitSyncWrapper<_.PartialObject<T>>;
|
||||
pickBy<T>(
|
||||
this: LoDashExplicitSyncWrapper<_.Dictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitSyncWrapper<_.Dictionary<T>>;
|
||||
pickBy<T>(
|
||||
this: LoDashExplicitSyncWrapper<_.NumericDictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitSyncWrapper<_.NumericDictionary<T>>;
|
||||
pickBy<T extends object>(
|
||||
this: LoDashExplicitSyncWrapper<T | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T[keyof T]>
|
||||
@@ -2841,6 +2857,14 @@ declare module "./index" {
|
||||
this: LoDashExplicitAsyncWrapper<T | null | undefined>,
|
||||
...paths: Array<_.Many<_.PropertyName>>
|
||||
): LoDashExplicitAsyncWrapper<_.PartialObject<T>>;
|
||||
omitBy<T>(
|
||||
this: LoDashExplicitAsyncWrapper<_.Dictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitAsyncWrapper<_.Dictionary<T>>;
|
||||
omitBy<T>(
|
||||
this: LoDashExplicitAsyncWrapper<_.NumericDictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitAsyncWrapper<_.NumericDictionary<T>>;
|
||||
omitBy<T extends object>(
|
||||
this: LoDashExplicitAsyncWrapper<T | null | undefined>,
|
||||
predicate: _.ValueKeyIteratee<T[keyof T]>
|
||||
@@ -2853,6 +2877,14 @@ declare module "./index" {
|
||||
this: LoDashExplicitAsyncWrapper<T | null | undefined>,
|
||||
...props: _.PropertyPath[]
|
||||
): LoDashExplicitAsyncWrapper<_.PartialObject<T>>;
|
||||
pickBy<T>(
|
||||
this: LoDashExplicitAsyncWrapper<_.Dictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitAsyncWrapper<_.Dictionary<T>>;
|
||||
pickBy<T>(
|
||||
this: LoDashExplicitAsyncWrapper<_.NumericDictionary<T> | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T>
|
||||
): LoDashExplicitAsyncWrapper<_.NumericDictionary<T>>;
|
||||
pickBy<T extends object>(
|
||||
this: LoDashExplicitAsyncWrapper<T | null | undefined>,
|
||||
predicate?: _.ValueKeyIteratee<T[keyof T]>
|
||||
|
||||
Reference in New Issue
Block a user