mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-17 12:16:38 +08:00
[fast-list] add typings
This commit is contained in:
89
types/fast-list/fast-list-tests.ts
Normal file
89
types/fast-list/fast-list-tests.ts
Normal 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
33
types/fast-list/index.d.ts
vendored
Normal 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[];
|
||||
}
|
||||
}
|
||||
22
types/fast-list/tsconfig.json
Normal file
22
types/fast-list/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",
|
||||
"fast-list-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/fast-list/tslint.json
Normal file
1
types/fast-list/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user