lodash - Add _.nth

This commit is contained in:
rzymek
2017-03-11 11:04:55 +01:00
parent f0b18c41f7
commit 6969dc0304
4 changed files with 86 additions and 1 deletions
+51
View File
@@ -2679,6 +2679,57 @@ declare namespace _ {
): LoDashExplicitWrapper<number>;
}
//_.nth
interface LoDashStatic {
/**
* Gets the element at index `n` of `array`. If `n` is negative, the nth element from the end is returned.
*
* @param array array The array to query.
* @param value The index of the element to return.
* @return Returns the nth element of `array`.
*/
nth<T>(
array: List<T>,
n?: number
): T;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.nth
*/
nth(
n?: number
): T;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.nth
*/
nth<TResult>(
n?:number
): TResult;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.nth
*/
nth(
n?:number
): LoDashExplicitWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.nth
*/
nth<TResult>(
n?:number
): LoDashExplicitWrapper<TResult>;
}
//_.pull
interface LoDashStatic {
/**
+31
View File
@@ -1289,6 +1289,37 @@ namespace TestLastIndexOf {
}
}
// _.nth
namespace TestNth {
let array: TResult[];
let list: _.List<TResult>;
let value: number;
{
let result: TResult;
result = _.nth<TResult>(array);
result = _.nth<TResult>(array, 42);
result = _(array).nth();
result = _(array).nth(42);
result = _(list).nth<TResult>();
result = _(list).nth<TResult>(42);
}
{
let result: _.LoDashExplicitWrapper<TResult>;
result = _(array).chain().nth();
result = _(array).chain().nth(42);
result = _(list).chain().nth<TResult>();
result = _(list).chain().nth<TResult>(42);
}
}
// _.pull
namespace TestPull {
let array: TResult[];
+2
View File
@@ -0,0 +1,2 @@
import { nth } from "../index";
export = nth;
+2 -1
View File
@@ -171,6 +171,7 @@
"noConflict/index.d.ts",
"noop/index.d.ts",
"now/index.d.ts",
"nth/index.d.ts",
"nthArg/index.d.ts",
"omit/index.d.ts",
"omitBy/index.d.ts",
@@ -306,4 +307,4 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}
}