diff --git a/types/yallist/index.d.ts b/types/yallist/index.d.ts new file mode 100644 index 0000000000..8a89697d82 --- /dev/null +++ b/types/yallist/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for yallist 3.0 +// Project: https://github.com/isaacs/yallist#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +export = Yallist; + +declare class Yallist implements Iterable { + static create(): Yallist; + static create(list: Yallist.ForEachIterable): Yallist; + static create(...items: T[]): Yallist; + + static Node: Yallist.NodeConstructor; + + head: Yallist.Node | null; + tail: Yallist.Node | null; + length: number; + + constructor(); + constructor(list: Yallist.ForEachIterable); + constructor(...items: T[]); + + forEach(callbackFn: (this: U, value: T, index: number, list: this) => void, thisArg?: U): void; + forEachReverse(callbackFn: (this: U, value: T, index: number, list: this) => void, thisArg?: U): void; + get(n: number): T | undefined; + getReverse(n: number): T | undefined; + map(callbackFn: (this: U, value: T, list: this) => R, thisArg?: U): Yallist; + mapReverse(callbackFn: (this: U, value: T, list: this) => R, thisArg?: U): Yallist; + pop(): T | undefined; + push(...items: T[]): number; + pushNode(node: Yallist.Node): void; + reduce(fn: (previousValue: U, currentValue: T, index: number) => U, initialValue?: U): U; + reduceReverse(fn: (previousValue: U, currentValue: T, index: number) => U, initialValue?: U): U; + removeNode(node: Yallist.Node): void; + reverse(): this; + shift(): T | undefined; + slice(from?: number, to?: number): Yallist; + sliceReverse(from?: number, to?: number): Yallist; + toArray(): T[]; + toArrayReverse(): T[]; + unshift(...items: T[]): number; + unshiftNode(node: Yallist.Node): void; + + [Symbol.iterator](): Iterator; +} + +declare namespace Yallist { + interface ForEachIterable { + forEach(callbackFn: (item: T) => void): void; + } + + interface NodeConstructor { + (value: T, prev?: Node, next?: Node, list?: Yallist): Node; + new (value: T, prev?: Node, next?: Node, list?: Yallist): Node; + } + + interface Node { + prev: Node | null; + next: Node | null; + list?: Yallist; + } +} diff --git a/types/yallist/tsconfig.json b/types/yallist/tsconfig.json new file mode 100644 index 0000000000..17b02a13c4 --- /dev/null +++ b/types/yallist/tsconfig.json @@ -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" + ] +} diff --git a/types/yallist/tslint.json b/types/yallist/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/yallist/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/yallist/yallist-tests.ts b/types/yallist/yallist-tests.ts new file mode 100644 index 0000000000..69099c0da9 --- /dev/null +++ b/types/yallist/yallist-tests.ts @@ -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([1, 2, 3]); // $ExpectType Yallist +Yallist.create(1, 2, 3); // $ExpectType Yallist +const myList = Yallist.create(forEachIterable); +myList; // $ExpectType Yallist + +new Yallist([1, 2, 3]); // $ExpectType Yallist +new Yallist(1, 2, 3); // $ExpectType Yallist +new Yallist(forEachIterable); // $ExpectType Yallist + +myList.forEach(function(v, i, l) { + v; // $ExpectType string + i; // $ExpectType number + l; // $ExpectType Yallist + this; // $ExpectType Yallist +}); +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 + this; // $ExpectType Yallist +}); +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 + this; // $ExpectType Yallist +}); +myList.map(function(v, l) { + this; // $ExpectType { someProp?: number | undefined; } +}, thisArg); +myList.mapReverse(function(v, l) { + v; // $ExpectType string + l; // $ExpectType Yallist + this; // $ExpectType Yallist +}); +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 + +myList.shift(); // $ExpectType string | undefined + +myList.slice(); // $ExpectType Yallist +myList.slice(0); // $ExpectType Yallist +myList.slice(1, -2); // $ExpectType Yallist +myList.sliceReverse(); // $ExpectType Yallist +myList.sliceReverse(0); // $ExpectType Yallist +myList.sliceReverse(1, -2); // $ExpectType Yallist + +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 +Yallist.Node('foo', node); +Yallist.Node('foo', node, node); +Yallist.Node('foo', node, node, myList); + +new Yallist.Node('foo'); // $ExpectType Node +new Yallist.Node('foo', node); +new Yallist.Node('foo', node, node); +new Yallist.Node('foo', node, node, myList); + +node.list; // $ExpectType Yallist | undefined +node.next; // $ExpectType Node | null +node.prev; // $ExpectType Node | null