Skip to content

Commit c75063a

Browse files
committed
Merge pull request DefinitelyTyped#8613 from chrootsu/lodash-update
lodash: added _.update
2 parents ecaf8c1 + 0d69060 commit c75063a

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

lodash/lodash-tests.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9843,6 +9843,51 @@ namespace TestUnset {
98439843
}
98449844
}
98459845

9846+
// _.update
9847+
namespace TestUpdate {
9848+
type SampleObject = {a: {}};
9849+
type SampleResult = {a: {b: number[]}};
9850+
9851+
let object: SampleObject;
9852+
let updater: (value: any) => number;
9853+
9854+
{
9855+
let result: SampleResult;
9856+
9857+
result = _.update<SampleResult>(object, 'a.b[1]', updater);
9858+
result = _.update<SampleResult>(object, ['a', 'b', 1], updater);
9859+
9860+
result = _.update<(value: any) => number, SampleResult>(object, 'a.b[1]', updater);
9861+
result = _.update<(value: any) => number, SampleResult>(object, ['a', 'b', 1], updater);
9862+
9863+
result = _.update<SampleObject, SampleResult>(object, 'a.b[1]', updater);
9864+
result = _.update<SampleObject, SampleResult>(object, ['a', 'b', 1], updater);
9865+
9866+
result = _.update<SampleObject, (value: any) => number, SampleResult>(object, 'a.b[1]', updater);
9867+
result = _.update<SampleObject, (value: any) => number, SampleResult>(object, ['a', 'b', 1], updater);
9868+
}
9869+
9870+
{
9871+
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
9872+
9873+
result = _(object).update<SampleResult>('a.b[1]', updater);
9874+
result = _(object).update<SampleResult>(['a', 'b', 1], updater);
9875+
9876+
result = _(object).update<(value: any) => number, SampleResult>('a.b[1]', updater);
9877+
result = _(object).update<(value: any) => number, SampleResult>(['a', 'b', 1], updater);
9878+
}
9879+
9880+
{
9881+
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
9882+
9883+
result = _(object).chain().update<SampleResult>('a.b[1]', updater);
9884+
result = _(object).chain().update<SampleResult>(['a', 'b', 1], updater);
9885+
9886+
result = _(object).chain().update<(value: any) => number, SampleResult>('a.b[1]', updater);
9887+
result = _(object).chain().update<(value: any) => number, SampleResult>(['a', 'b', 1], updater);
9888+
}
9889+
}
9890+
98469891
// _.values
98479892
namespace TestValues {
98489893
let object: _.Dictionary<TResult>;

lodash/lodash.d.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16479,6 +16479,87 @@ declare module _ {
1647916479
unset(path: StringRepresentable|StringRepresentable[]): LoDashExplicitWrapper<boolean>;
1648016480
}
1648116481

16482+
//_.update
16483+
interface LoDashStatic {
16484+
/**
16485+
* This method is like _.set except that accepts updater to produce the value to set. Use _.updateWith to
16486+
* customize path creation. The updater is invoked with one argument: (value).
16487+
*
16488+
* @param object The object to modify.
16489+
* @param path The path of the property to set.
16490+
* @param updater The function to produce the updated value.
16491+
* @return Returns object.
16492+
*/
16493+
update<TResult>(
16494+
object: Object,
16495+
path: StringRepresentable|StringRepresentable[],
16496+
updater: Function
16497+
): TResult;
16498+
16499+
/**
16500+
* @see _.update
16501+
*/
16502+
update<U extends Function, TResult>(
16503+
object: Object,
16504+
path: StringRepresentable|StringRepresentable[],
16505+
updater: U
16506+
): TResult;
16507+
16508+
/**
16509+
* @see _.update
16510+
*/
16511+
update<O extends {}, TResult>(
16512+
object: O,
16513+
path: StringRepresentable|StringRepresentable[],
16514+
updater: Function
16515+
): TResult;
16516+
16517+
/**
16518+
* @see _.update
16519+
*/
16520+
update<O, U extends Function, TResult>(
16521+
object: O,
16522+
path: StringRepresentable|StringRepresentable[],
16523+
updater: U
16524+
): TResult;
16525+
}
16526+
16527+
interface LoDashImplicitObjectWrapper<T> {
16528+
/**
16529+
* @see _.update
16530+
*/
16531+
update<TResult>(
16532+
path: StringRepresentable|StringRepresentable[],
16533+
updater: any
16534+
): LoDashImplicitObjectWrapper<TResult>;
16535+
16536+
/**
16537+
* @see _.update
16538+
*/
16539+
update<U extends Function, TResult>(
16540+
path: StringRepresentable|StringRepresentable[],
16541+
updater: U
16542+
): LoDashImplicitObjectWrapper<TResult>;
16543+
}
16544+
16545+
interface LoDashExplicitObjectWrapper<T> {
16546+
/**
16547+
* @see _.update
16548+
*/
16549+
update<TResult>(
16550+
path: StringRepresentable|StringRepresentable[],
16551+
updater: any
16552+
): LoDashExplicitObjectWrapper<TResult>;
16553+
16554+
/**
16555+
* @see _.update
16556+
*/
16557+
update<U extends Function, TResult>(
16558+
path: StringRepresentable|StringRepresentable[],
16559+
updater: U
16560+
): LoDashExplicitObjectWrapper<TResult>;
16561+
}
16562+
1648216563
//_.values
1648316564
interface LoDashStatic {
1648416565
/**

0 commit comments

Comments
 (0)