Merge pull request #8613 from chrootsu/lodash-update

lodash: added _.update
This commit is contained in:
Masahiro Wakame
2016-03-19 14:37:33 +09:00
2 changed files with 126 additions and 0 deletions
+45
View File
@@ -9843,6 +9843,51 @@ namespace TestUnset {
}
}
// _.update
namespace TestUpdate {
type SampleObject = {a: {}};
type SampleResult = {a: {b: number[]}};
let object: SampleObject;
let updater: (value: any) => number;
{
let result: SampleResult;
result = _.update<SampleResult>(object, 'a.b[1]', updater);
result = _.update<SampleResult>(object, ['a', 'b', 1], updater);
result = _.update<(value: any) => number, SampleResult>(object, 'a.b[1]', updater);
result = _.update<(value: any) => number, SampleResult>(object, ['a', 'b', 1], updater);
result = _.update<SampleObject, SampleResult>(object, 'a.b[1]', updater);
result = _.update<SampleObject, SampleResult>(object, ['a', 'b', 1], updater);
result = _.update<SampleObject, (value: any) => number, SampleResult>(object, 'a.b[1]', updater);
result = _.update<SampleObject, (value: any) => number, SampleResult>(object, ['a', 'b', 1], updater);
}
{
let result: _.LoDashImplicitObjectWrapper<SampleResult>;
result = _(object).update<SampleResult>('a.b[1]', updater);
result = _(object).update<SampleResult>(['a', 'b', 1], updater);
result = _(object).update<(value: any) => number, SampleResult>('a.b[1]', updater);
result = _(object).update<(value: any) => number, SampleResult>(['a', 'b', 1], updater);
}
{
let result: _.LoDashExplicitObjectWrapper<SampleResult>;
result = _(object).chain().update<SampleResult>('a.b[1]', updater);
result = _(object).chain().update<SampleResult>(['a', 'b', 1], updater);
result = _(object).chain().update<(value: any) => number, SampleResult>('a.b[1]', updater);
result = _(object).chain().update<(value: any) => number, SampleResult>(['a', 'b', 1], updater);
}
}
// _.values
namespace TestValues {
let object: _.Dictionary<TResult>;
+81
View File
@@ -16479,6 +16479,87 @@ declare module _ {
unset(path: StringRepresentable|StringRepresentable[]): LoDashExplicitWrapper<boolean>;
}
//_.update
interface LoDashStatic {
/**
* This method is like _.set except that accepts updater to produce the value to set. Use _.updateWith to
* customize path creation. The updater is invoked with one argument: (value).
*
* @param object The object to modify.
* @param path The path of the property to set.
* @param updater The function to produce the updated value.
* @return Returns object.
*/
update<TResult>(
object: Object,
path: StringRepresentable|StringRepresentable[],
updater: Function
): TResult;
/**
* @see _.update
*/
update<U extends Function, TResult>(
object: Object,
path: StringRepresentable|StringRepresentable[],
updater: U
): TResult;
/**
* @see _.update
*/
update<O extends {}, TResult>(
object: O,
path: StringRepresentable|StringRepresentable[],
updater: Function
): TResult;
/**
* @see _.update
*/
update<O, U extends Function, TResult>(
object: O,
path: StringRepresentable|StringRepresentable[],
updater: U
): TResult;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.update
*/
update<TResult>(
path: StringRepresentable|StringRepresentable[],
updater: any
): LoDashImplicitObjectWrapper<TResult>;
/**
* @see _.update
*/
update<U extends Function, TResult>(
path: StringRepresentable|StringRepresentable[],
updater: U
): LoDashImplicitObjectWrapper<TResult>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.update
*/
update<TResult>(
path: StringRepresentable|StringRepresentable[],
updater: any
): LoDashExplicitObjectWrapper<TResult>;
/**
* @see _.update
*/
update<U extends Function, TResult>(
path: StringRepresentable|StringRepresentable[],
updater: U
): LoDashExplicitObjectWrapper<TResult>;
}
//_.values
interface LoDashStatic {
/**