diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 5b9add244..56734e3a4 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -135,8 +135,6 @@ result = _([1, 2, 3, 4]).pop(); result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).push(5, 6, 7); result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).reverse(); result = _([1, 2, 3, 4]).shift(); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).slice(1, 2); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).slice(2); result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).sort((a, b) => 1); result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1); result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1, 2, 5, 6); @@ -315,6 +313,18 @@ result = _.remove(foodsOrganic, 'organic'); result = _.remove(foodsType, { 'type': 'vegetable' }); var typedResult: IFoodType[] = _.remove([ { name: 'apple' }, { name: 'orange' }], { name: 'orange' }); +// _.slice +{ + let testSliceArray: TResult[]; + let result: TResult[]; + result = _.slice(testSliceArray); + result = _.slice(testSliceArray, 42); + result = _.slice(testSliceArray, 42, 42); + result = _(testSliceArray).slice().value(); + result = _(testSliceArray).slice(42).value(); + result = _(testSliceArray).slice(42, 42).value(); +} + result = _.sortedIndex([20, 30, 50], 40); result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); var sortedIndexDict: { wordToNumber: { [idx: string]: number } } = { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b6c95710b..bdc6d129e 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -258,7 +258,6 @@ declare module _ { push(...items: T[]): LoDashArrayWrapper; reverse(): LoDashArrayWrapper; shift(): T; - slice(start: number, end?: number): LoDashArrayWrapper; sort(compareFn?: (a: T, b: T) => number): LoDashArrayWrapper; splice(start: number): LoDashArrayWrapper; splice(start: number, deleteCount: number, ...items: any[]): LoDashArrayWrapper; @@ -1417,6 +1416,33 @@ declare module _ { whereValue: W): T[]; } + //_.slice + interface LoDashStatic { + /** + * Creates a slice of array from start up to, but not including, end. + * + * @param array The array to slice. + * @param start The start position. + * @param end The end position. + * @return Returns the slice of array. + */ + slice( + array: T[], + start?: number, + end?: number + ): T[]; + } + + interface LoDashArrayWrapper { + /** + * @see _.slice + */ + slice( + start?: number, + end?: number + ): LoDashArrayWrapper; + } + //_.sortedIndex interface LoDashStatic { /**