Skip to content

Commit 0d69060

Browse files
committed
lodash: added _.update
1 parent 99579ab commit 0d69060

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
@@ -9619,6 +9619,51 @@ namespace TestUnset {
96199619
}
96209620
}
96219621

9622+
// _.update
9623+
namespace TestUpdate {
9624+
type SampleObject = {a: {}};
9625+
type SampleResult = {a: {b: number[]}};
9626+
9627+
let object: SampleObject;
9628+
let updater: (value: any) => number;
9629+
9630+
{
9631+
let result: SampleResult;
9632+
9633+
result = _.update<SampleResult>(object, 'a.b[1]', updater);
9634+
result = _.update<SampleResult>(object, ['a', 'b', 1], updater);
9635+
9636+
result = _.update<(value: any) => number, SampleResult>(object, 'a.b[1]', updater);
9637+
result = _.update<(value: any) => number, SampleResult>(object, ['a', 'b', 1], updater);
9638+
9639+
result = _.update<SampleObject, SampleResult>(object, 'a.b[1]', updater);
9640+
result = _.update<SampleObject, SampleResult>(object, ['a', 'b', 1], updater);
9641+
9642+
result = _.update<SampleObject, (value: any) => number, SampleResult>(object, 'a.b[1]', updater);
9643+
result = _.update<SampleObject, (value: any) => number, SampleResult>(object, ['a', 'b', 1], updater);
9644+
}
9645+
9646+
{
9647+
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
9648+
9649+
result = _(object).update<SampleResult>('a.b[1]', updater);
9650+
result = _(object).update<SampleResult>(['a', 'b', 1], updater);
9651+
9652+
result = _(object).update<(value: any) => number, SampleResult>('a.b[1]', updater);
9653+
result = _(object).update<(value: any) => number, SampleResult>(['a', 'b', 1], updater);
9654+
}
9655+
9656+
{
9657+
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
9658+
9659+
result = _(object).chain().update<SampleResult>('a.b[1]', updater);
9660+
result = _(object).chain().update<SampleResult>(['a', 'b', 1], updater);
9661+
9662+
result = _(object).chain().update<(value: any) => number, SampleResult>('a.b[1]', updater);
9663+
result = _(object).chain().update<(value: any) => number, SampleResult>(['a', 'b', 1], updater);
9664+
}
9665+
}
9666+
96229667
// _.values
96239668
module TestValues {
96249669
let object: _.Dictionary<TResult>;

lodash/lodash.d.ts

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

16219+
//_.update
16220+
interface LoDashStatic {
16221+
/**
16222+
* This method is like _.set except that accepts updater to produce the value to set. Use _.updateWith to
16223+
* customize path creation. The updater is invoked with one argument: (value).
16224+
*
16225+
* @param object The object to modify.
16226+
* @param path The path of the property to set.
16227+
* @param updater The function to produce the updated value.
16228+
* @return Returns object.
16229+
*/
16230+
update<TResult>(
16231+
object: Object,
16232+
path: StringRepresentable|StringRepresentable[],
16233+
updater: Function
16234+
): TResult;
16235+
16236+
/**
16237+
* @see _.update
16238+
*/
16239+
update<U extends Function, TResult>(
16240+
object: Object,
16241+
path: StringRepresentable|StringRepresentable[],
16242+
updater: U
16243+
): TResult;
16244+
16245+
/**
16246+
* @see _.update
16247+
*/
16248+
update<O extends {}, TResult>(
16249+
object: O,
16250+
path: StringRepresentable|StringRepresentable[],
16251+
updater: Function
16252+
): TResult;
16253+
16254+
/**
16255+
* @see _.update
16256+
*/
16257+
update<O, U extends Function, TResult>(
16258+
object: O,
16259+
path: StringRepresentable|StringRepresentable[],
16260+
updater: U
16261+
): TResult;
16262+
}
16263+
16264+
interface LoDashImplicitObjectWrapper<T> {
16265+
/**
16266+
* @see _.update
16267+
*/
16268+
update<TResult>(
16269+
path: StringRepresentable|StringRepresentable[],
16270+
updater: any
16271+
): LoDashImplicitObjectWrapper<TResult>;
16272+
16273+
/**
16274+
* @see _.update
16275+
*/
16276+
update<U extends Function, TResult>(
16277+
path: StringRepresentable|StringRepresentable[],
16278+
updater: U
16279+
): LoDashImplicitObjectWrapper<TResult>;
16280+
}
16281+
16282+
interface LoDashExplicitObjectWrapper<T> {
16283+
/**
16284+
* @see _.update
16285+
*/
16286+
update<TResult>(
16287+
path: StringRepresentable|StringRepresentable[],
16288+
updater: any
16289+
): LoDashExplicitObjectWrapper<TResult>;
16290+
16291+
/**
16292+
* @see _.update
16293+
*/
16294+
update<U extends Function, TResult>(
16295+
path: StringRepresentable|StringRepresentable[],
16296+
updater: U
16297+
): LoDashExplicitObjectWrapper<TResult>;
16298+
}
16299+
1621916300
//_.values
1622016301
interface LoDashStatic {
1622116302
/**

0 commit comments

Comments
 (0)