diff --git a/types/fast-list/fast-list-tests.ts b/types/fast-list/fast-list-tests.ts new file mode 100644 index 0000000000..68e0fc6faf --- /dev/null +++ b/types/fast-list/fast-list-tests.ts @@ -0,0 +1,89 @@ +import FastList = require('fast-list'); + +const thisArg = {foo: 'bar'}; + +const list = new FastList(); +list; // $ExpectType List +FastList(); // $ExpectType List + +list.length; // $ExpectType number +list.length = 1; // $ExpectError + +list.push('foo'); +list.pop(); // $ExpectType string | undefined +list.unshift('bar'); +list.shift(); // $ExpectType string | undefined +list.drop(); +list.item(2); // $ExpectType string | undefined + +list.map(function(value, index, list) { // $ExpectType List + this; // $ExpectType List + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List + return value; +}); +list.map(function(value, index, list) { // $ExpectType List + this; // $ExpectType { foo: string; } + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List + return 1; +}, thisArg); + +list.reduce(function(prevVal, value, index, list) { // $ExpectType string + this; // $ExpectType List + prevVal; // $ExpectType string + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List + return prevVal; +}); +list.reduce(function(prevVal, value, index, list) { // $ExpectType number + this; // $ExpectType List + prevVal; // $ExpectType number + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List + return prevVal; +}, 1); +list.reduce(function(prevVal, value, index, list) { // $ExpectType number + this; // $ExpectType { foo: string; } + prevVal; // $ExpectType number + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List + return prevVal; +}, 1, thisArg); + +list.forEach(function(value, index, list) { + this; // $ExpectType List + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List +}); +list.forEach(function(value, index, list) { + this; // $ExpectType { foo: string; } + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List +}, thisArg); + +list.filter(function(value, index, list) { // $ExpectType List + this; // $ExpectType List + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List + return true; +}); +list.filter(function(value, index, list) { // $ExpectType List + this; // $ExpectType { foo: string; } + value; // $ExpectType string + index; // $ExpectType number + list; // $ExpectType List + return true; +}, thisArg); + +list.slice(); // $ExpectType string[] +list.slice(1); // $ExpectType string[] +list.slice(1, -2); // $ExpectType string[] diff --git a/types/fast-list/index.d.ts b/types/fast-list/index.d.ts new file mode 100644 index 0000000000..2ac8fdaad0 --- /dev/null +++ b/types/fast-list/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for fast-list 1.0 +// Project: https://github.com/isaacs/fast-list#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +export as namespace FastList; +export = FastList; + +declare const FastList: FastListFactory; + +interface FastListFactory { + (): FastList.List; + new (): FastList.List; +} + +declare namespace FastList { + interface List { + readonly length: number; + + push(item: T): void; + pop(): T | undefined; + unshift(item: T): void; + shift(): T | undefined; + drop(): void; + item(index: number): T | undefined; + map (callbackfn: (this: V, value: T, index: number, list: this) => U, thisArg?: V): List; + reduce (callbackfn: (this: V, acc: U, value: T, index: number, list: this) => U, initialValue?: U, thisArg?: V): U; + forEach (callbackfn: (this: U, value: T, index: number, list: this) => void, thisArg?: U): void; + filter (callbackfn: (this: U, value: T, index: number, list: this) => boolean, thisArg?: U): List; + slice(start?: number, end?: number): T[]; + } +} diff --git a/types/fast-list/tsconfig.json b/types/fast-list/tsconfig.json new file mode 100644 index 0000000000..a639b60ffe --- /dev/null +++ b/types/fast-list/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", + "fast-list-tests.ts" + ] +} diff --git a/types/fast-list/tslint.json b/types/fast-list/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fast-list/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }