mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-07 22:38:13 +08:00
[yallist] add typings
This commit is contained in:
63
types/yallist/index.d.ts
vendored
Normal file
63
types/yallist/index.d.ts
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
// Type definitions for yallist 3.0
|
||||
// Project: https://github.com/isaacs/yallist#readme
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
export = Yallist;
|
||||
|
||||
declare class Yallist<T> implements Iterable<T> {
|
||||
static create<T>(): Yallist<T>;
|
||||
static create<T>(list: Yallist.ForEachIterable<T>): Yallist<T>;
|
||||
static create<T>(...items: T[]): Yallist<T>;
|
||||
|
||||
static Node: Yallist.NodeConstructor;
|
||||
|
||||
head: Yallist.Node<T> | null;
|
||||
tail: Yallist.Node<T> | null;
|
||||
length: number;
|
||||
|
||||
constructor();
|
||||
constructor(list: Yallist.ForEachIterable<T>);
|
||||
constructor(...items: T[]);
|
||||
|
||||
forEach<U = this>(callbackFn: (this: U, value: T, index: number, list: this) => void, thisArg?: U): void;
|
||||
forEachReverse<U = this>(callbackFn: (this: U, value: T, index: number, list: this) => void, thisArg?: U): void;
|
||||
get(n: number): T | undefined;
|
||||
getReverse(n: number): T | undefined;
|
||||
map<U = this, R = T>(callbackFn: (this: U, value: T, list: this) => R, thisArg?: U): Yallist<R>;
|
||||
mapReverse<U = this, R = T>(callbackFn: (this: U, value: T, list: this) => R, thisArg?: U): Yallist<R>;
|
||||
pop(): T | undefined;
|
||||
push(...items: T[]): number;
|
||||
pushNode(node: Yallist.Node<T>): void;
|
||||
reduce<U = T>(fn: (previousValue: U, currentValue: T, index: number) => U, initialValue?: U): U;
|
||||
reduceReverse<U = T>(fn: (previousValue: U, currentValue: T, index: number) => U, initialValue?: U): U;
|
||||
removeNode(node: Yallist.Node<T>): void;
|
||||
reverse(): this;
|
||||
shift(): T | undefined;
|
||||
slice(from?: number, to?: number): Yallist<T>;
|
||||
sliceReverse(from?: number, to?: number): Yallist<T>;
|
||||
toArray(): T[];
|
||||
toArrayReverse(): T[];
|
||||
unshift(...items: T[]): number;
|
||||
unshiftNode(node: Yallist.Node<T>): void;
|
||||
|
||||
[Symbol.iterator](): Iterator<T>;
|
||||
}
|
||||
|
||||
declare namespace Yallist {
|
||||
interface ForEachIterable<T> {
|
||||
forEach(callbackFn: (item: T) => void): void;
|
||||
}
|
||||
|
||||
interface NodeConstructor {
|
||||
<T>(value: T, prev?: Node<T>, next?: Node<T>, list?: Yallist<T>): Node<T>;
|
||||
new <T>(value: T, prev?: Node<T>, next?: Node<T>, list?: Yallist<T>): Node<T>;
|
||||
}
|
||||
|
||||
interface Node<T> {
|
||||
prev: Node<T> | null;
|
||||
next: Node<T> | null;
|
||||
list?: Yallist<T>;
|
||||
}
|
||||
}
|
||||
22
types/yallist/tsconfig.json
Normal file
22
types/yallist/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"yallist-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/yallist/tslint.json
Normal file
1
types/yallist/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
117
types/yallist/yallist-tests.ts
Normal file
117
types/yallist/yallist-tests.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import Yallist = require('yallist');
|
||||
|
||||
const forEachIterable = {
|
||||
forEach(fn: (item: string, idx: number) => void, thisArg?: any) {},
|
||||
};
|
||||
const thisArg: {someProp?: number} = {};
|
||||
const node = new Yallist.Node('foo');
|
||||
|
||||
Yallist.create<string | number>([1, 2, 3]); // $ExpectType Yallist<string | number>
|
||||
Yallist.create<string | number>(1, 2, 3); // $ExpectType Yallist<string | number>
|
||||
const myList = Yallist.create(forEachIterable);
|
||||
myList; // $ExpectType Yallist<string>
|
||||
|
||||
new Yallist<string | number>([1, 2, 3]); // $ExpectType Yallist<string | number>
|
||||
new Yallist<string | number>(1, 2, 3); // $ExpectType Yallist<string | number>
|
||||
new Yallist(forEachIterable); // $ExpectType Yallist<string>
|
||||
|
||||
myList.forEach(function(v, i, l) {
|
||||
v; // $ExpectType string
|
||||
i; // $ExpectType number
|
||||
l; // $ExpectType Yallist<string>
|
||||
this; // $ExpectType Yallist<string>
|
||||
});
|
||||
myList.forEach(function(v, i, l) {
|
||||
this; // $ExpectType { someProp?: number | undefined; }
|
||||
}, thisArg);
|
||||
myList.forEachReverse(function(v, i, l) {
|
||||
v; // $ExpectType string
|
||||
i; // $ExpectType number
|
||||
l; // $ExpectType Yallist<string>
|
||||
this; // $ExpectType Yallist<string>
|
||||
});
|
||||
myList.forEachReverse(function(v, i, l) {
|
||||
this; // $ExpectType { someProp?: number | undefined; }
|
||||
}, thisArg);
|
||||
|
||||
myList.get(2); // $ExpectType string | undefined
|
||||
myList.getReverse(2); // $ExpectType string | undefined
|
||||
|
||||
myList.map(function(v, l) {
|
||||
v; // $ExpectType string
|
||||
l; // $ExpectType Yallist<string>
|
||||
this; // $ExpectType Yallist<string>
|
||||
});
|
||||
myList.map(function(v, l) {
|
||||
this; // $ExpectType { someProp?: number | undefined; }
|
||||
}, thisArg);
|
||||
myList.mapReverse(function(v, l) {
|
||||
v; // $ExpectType string
|
||||
l; // $ExpectType Yallist<string>
|
||||
this; // $ExpectType Yallist<string>
|
||||
});
|
||||
myList.mapReverse(function(v, l) {
|
||||
this; // $ExpectType { someProp?: number | undefined; }
|
||||
}, thisArg);
|
||||
|
||||
myList.pop(); // $ExpectType string | undefined
|
||||
|
||||
myList.push(); // $ExpectType number
|
||||
myList.push('foo'); // $ExpectType number
|
||||
myList.push('foo', 'bar'); // $ExpectType number
|
||||
|
||||
myList.reduce((acc, v, i) => { // $ExpectType string
|
||||
acc; // $ExpectType string
|
||||
v; // $ExpectType string
|
||||
i; // $ExpectType number
|
||||
return acc;
|
||||
});
|
||||
myList.reduce((acc, v) => { // $ExpectType boolean
|
||||
acc; // $ExpectType boolean
|
||||
return acc;
|
||||
}, true);
|
||||
myList.reduceReverse((acc, v, i) => { // $ExpectType string
|
||||
acc; // $ExpectType string
|
||||
v; // $ExpectType string
|
||||
i; // $ExpectType number
|
||||
return acc;
|
||||
});
|
||||
myList.reduceReverse((acc, v) => { // $ExpectType boolean
|
||||
acc; // $ExpectType boolean
|
||||
return acc;
|
||||
}, true);
|
||||
|
||||
myList.reverse(); // $ExpectType Yallist<string>
|
||||
|
||||
myList.shift(); // $ExpectType string | undefined
|
||||
|
||||
myList.slice(); // $ExpectType Yallist<string>
|
||||
myList.slice(0); // $ExpectType Yallist<string>
|
||||
myList.slice(1, -2); // $ExpectType Yallist<string>
|
||||
myList.sliceReverse(); // $ExpectType Yallist<string>
|
||||
myList.sliceReverse(0); // $ExpectType Yallist<string>
|
||||
myList.sliceReverse(1, -2); // $ExpectType Yallist<string>
|
||||
|
||||
myList.toArray(); // $ExpectType string[]
|
||||
myList.toArrayReverse(); // $ExpectType string[]
|
||||
|
||||
myList.unshift('bar'); // $ExpectType number
|
||||
myList.unshift('bar', 'baz'); // $ExpectType number
|
||||
|
||||
myList.pushNode(myList.head || node);
|
||||
myList.removeNode(myList.tail || node);
|
||||
myList.unshiftNode(myList.tail || node);
|
||||
|
||||
Yallist.Node('foo'); // $ExpectType Node<string>
|
||||
Yallist.Node('foo', node);
|
||||
Yallist.Node('foo', node, node);
|
||||
Yallist.Node('foo', node, node, myList);
|
||||
|
||||
new Yallist.Node('foo'); // $ExpectType Node<string>
|
||||
new Yallist.Node('foo', node);
|
||||
new Yallist.Node('foo', node, node);
|
||||
new Yallist.Node('foo', node, node, myList);
|
||||
|
||||
node.list; // $ExpectType Yallist<string> | undefined
|
||||
node.next; // $ExpectType Node<string> | null
|
||||
node.prev; // $ExpectType Node<string> | null
|
||||
Reference in New Issue
Block a user