mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
lodash: added _.update
This commit is contained in:
@@ -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>;
|
||||
|
||||
Vendored
+81
@@ -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 {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user