diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 525719576..eb74bd0bb 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -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(object, 'a.b[1]', updater); + result = _.update(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(object, 'a.b[1]', updater); + result = _.update(object, ['a', 'b', 1], updater); + + result = _.update number, SampleResult>(object, 'a.b[1]', updater); + result = _.update number, SampleResult>(object, ['a', 'b', 1], updater); + } + + { + let result: _.LoDashImplicitObjectWrapper; + + result = _(object).update('a.b[1]', updater); + result = _(object).update(['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; + + result = _(object).chain().update('a.b[1]', updater); + result = _(object).chain().update(['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; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 858e56ab9..28c29ad9d 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -16479,6 +16479,87 @@ declare module _ { unset(path: StringRepresentable|StringRepresentable[]): LoDashExplicitWrapper; } + //_.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( + object: Object, + path: StringRepresentable|StringRepresentable[], + updater: Function + ): TResult; + + /** + * @see _.update + */ + update( + object: Object, + path: StringRepresentable|StringRepresentable[], + updater: U + ): TResult; + + /** + * @see _.update + */ + update( + object: O, + path: StringRepresentable|StringRepresentable[], + updater: Function + ): TResult; + + /** + * @see _.update + */ + update( + object: O, + path: StringRepresentable|StringRepresentable[], + updater: U + ): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: any + ): LoDashImplicitObjectWrapper; + + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: U + ): LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: U + ): LoDashExplicitObjectWrapper; + } + //_.values interface LoDashStatic { /**