diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index ee57f01f1..24bf22118 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -93,6 +93,19 @@ result = <_.LoDashWrapper>_(['test1', 'test2']).chain(); result = <_.LoDashWrapper>_.chain('test'); result = <_.LoDashWrapper>_.chain(['test1', 'test2']); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).concat([5, 6, 7]); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).join(','); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).pop(); +_([1, 2, 3, 4]).push(5, 6, 7); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).reverse(); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).shift(); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).slice(1, 2); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).slice(2); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).sort((a, b) => 1); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).splice(1); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).splice(1, 2, 5, 6); +result = <_.LoDashWrapper>_([1, 2, 3, 4]).unshift(5, 6); + result = _.tap([1, 2, 3, 4], function(array) { console.log(array); }); result = <_.LoDashWrapper>_([1, 2, 3, 4]).tap(function(array) { console.log(array); }); @@ -483,8 +496,8 @@ var greet = function(formatted) { return 'Hiya ' + formatted + '!'; }; -var welcome: Function = _.compose(greet, format); -welcome('curly'); +result = _.compose(greet, format); +result = <_.LoDashWrapper>_(greet).compose(format); var createCallbackObj = { name: 'Joe' }; var pluckCallback: () => any = _.createCallback('name'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index fb935bb6b..d72628d5a 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -6,16 +6,42 @@ // Heavily based on Underscore definitions by Boris Yankov /** -* Lo-Dash OOP Wrapper, all Lo-Dash functions that take an object -* as the first parameter can be invoked through this function. -* @param key First argument to Lo-Dash object functions. +* Creates a lodash object which wraps the given value to enable intuitive method chaining. +* +* In addition to Lo-Dash methods, wrappers also have the following Array methods: +* concat, join, pop, push, reverse, shift, slice, sort, splice, and unshift +* +* Chaining is supported in custom builds as long as the value method is implicitly or explicitly +* included in the build. +* +* The chainable wrapper functions are: +* after, assign, bind, bindAll, bindKey, chain, compact, compose, concat, countBy, createCallback, +* curry, debounce, defaults, defer, delay, difference, filter, flatten, forEach, forEachRight, +* forIn, forInRight, forOwn, forOwnRight, functions, groupBy, indexBy, initial, intersection, +* invert, invoke, keys, map, max, memoize, merge, min, object, omit, once, pairs, partial, +* partialRight, pick, pluck, pull, push, range, reject, remove, rest, reverse, shuffle, slice, sort, +* sortBy, splice, tap, throttle, times, toArray, transform, union, uniq, unshift, unzip, values, +* where, without, wrap, and zip +* +* The non-chainable wrapper functions are: +* clone, cloneDeep, contains, escape, every, find, findIndex, findKey, findLast, findLastIndex, +* findLastKey, has, identity, indexOf, isArguments, isArray, isBoolean, isDate, isElement, isEmpty, +* isEqual, isFinite, isFunction, isNaN, isNull, isNumber, isObject, isPlainObject, isRegExp, +* isString, isUndefined, join, lastIndexOf, mixin, noConflict, parseInt, pop, random, reduce, +* reduceRight, result, shift, size, some, sortedIndex, runInContext, template, unescape, uniqueId, +* and value +* +* The wrapper functions first and last return wrapped values when n is provided, otherwise they +* return unwrapped values. +* +* Explicit chaining can be enabled by using the _.chain method. +* @param value The value to wrap in a lodash instance. +* @return A lodash instance. **/ -declare function _(value: Array): _.LoDashWrapper>; declare function _(value: T): _.LoDashWrapper; +declare function _(value: T[]): _.LoDashWrapper; declare module _ { - interface LoDashWrapper {} - /** * lodash.js _.debounce options **/ @@ -190,6 +216,21 @@ declare module _ { /********* * Chaining * **********/ + + //Wrapper Array methods + interface LoDashWrapper { + concat(...items: any[]): LoDashWrapper; + join(seperator?: string): LoDashWrapper; + pop(): LoDashWrapper; + push(...items: any[]): void; + reverse(): LoDashWrapper; + shift(): LoDashWrapper; + slice(start: number, end?: number): LoDashWrapper; + sort(compareFn?: (a: any, b: any) => number): LoDashWrapper; + splice(start: number): LoDashWrapper; + splice(start: number, deleteCount: number, ...items: any[]): LoDashWrapper; + unshift(...items: any[]): LoDashWrapper; + } /** * Creates a lodash object that wraps the given value with explicit method chaining enabled. @@ -1970,6 +2011,13 @@ declare module _ { **/ export function compose(...funcs: Function[]): Function; + interface LoDashWrapper { + /** + * @see _.compose + **/ + compose(...funcs: Function[]): LoDashWrapper; + } + /** * Produces a callback bound to an optional thisArg. If func is a property name the created * callback will return the property value for a given element. If func is an object the created