lodash: added _.update

This commit is contained in:
Ilya Mochalov
2016-03-03 21:27:59 +05:00
parent 99579ab6ae
commit 0d69060029
2 changed files with 126 additions and 0 deletions
+45
View File
@@ -9619,6 +9619,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
module TestValues {
let object: _.Dictionary<TResult>;
+81
View File
@@ -16216,6 +16216,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 {
/**