[fast-list] add typings

This commit is contained in:
Dimitri Benin
2017-08-24 17:41:39 +02:00
parent 76a13f1ad8
commit 75c5dfbee4
4 changed files with 145 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
import FastList = require('fast-list');
const thisArg = {foo: 'bar'};
const list = new FastList<string>();
list; // $ExpectType List<string>
FastList<number>(); // $ExpectType List<number>
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<string>
this; // $ExpectType List<string>
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
return value;
});
list.map(function(value, index, list) { // $ExpectType List<number>
this; // $ExpectType { foo: string; }
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
return 1;
}, thisArg);
list.reduce(function(prevVal, value, index, list) { // $ExpectType string
this; // $ExpectType List<string>
prevVal; // $ExpectType string
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
return prevVal;
});
list.reduce(function(prevVal, value, index, list) { // $ExpectType number
this; // $ExpectType List<string>
prevVal; // $ExpectType number
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
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<string>
return prevVal;
}, 1, thisArg);
list.forEach(function(value, index, list) {
this; // $ExpectType List<string>
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
});
list.forEach(function(value, index, list) {
this; // $ExpectType { foo: string; }
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
}, thisArg);
list.filter(function(value, index, list) { // $ExpectType List<string>
this; // $ExpectType List<string>
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
return true;
});
list.filter(function(value, index, list) { // $ExpectType List<string>
this; // $ExpectType { foo: string; }
value; // $ExpectType string
index; // $ExpectType number
list; // $ExpectType List<string>
return true;
}, thisArg);
list.slice(); // $ExpectType string[]
list.slice(1); // $ExpectType string[]
list.slice(1, -2); // $ExpectType string[]

33
types/fast-list/index.d.ts vendored Normal file
View File

@@ -0,0 +1,33 @@
// Type definitions for fast-list 1.0
// Project: https://github.com/isaacs/fast-list#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export as namespace FastList;
export = FastList;
declare const FastList: FastListFactory;
interface FastListFactory {
<T>(): FastList.List<T>;
new <T>(): FastList.List<T>;
}
declare namespace FastList {
interface List<T> {
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 <U = T, V = this>(callbackfn: (this: V, value: T, index: number, list: this) => U, thisArg?: V): List<U>;
reduce <U = T, V = this>(callbackfn: (this: V, acc: U, value: T, index: number, list: this) => U, initialValue?: U, thisArg?: V): U;
forEach <U = this>(callbackfn: (this: U, value: T, index: number, list: this) => void, thisArg?: U): void;
filter <U = this>(callbackfn: (this: U, value: T, index: number, list: this) => boolean, thisArg?: U): List<T>;
slice(start?: number, end?: number): T[];
}
}

View 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",
"fast-list-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }