mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-19 16:49:45 +08:00
reservoir typings
This commit is contained in:
35
types/reservoir/index.d.ts
vendored
Normal file
35
types/reservoir/index.d.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Type definitions for reservoir 0.1
|
||||
// Project: https://github.com/imbcmdth/reservoir
|
||||
// Definitions by: Dan Vanderkam <https://github.com/danvk>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export as namespace Reservoir;
|
||||
export = Reservoir;
|
||||
|
||||
/**
|
||||
* Create a new reservoir sampler.
|
||||
*
|
||||
* @param reservoirSize is the maximum size of the reservoir. This is the number of elements
|
||||
* to be randomly chosen from the input provided to it using pushSome. Default is 1.
|
||||
* @param randomNumberGenerator is an optional random number generating function to use in
|
||||
* place of the default Math.random.
|
||||
*/
|
||||
declare function Reservoir<T>(
|
||||
reservoirSize?: number,
|
||||
randomNumberGenerator?: () => number
|
||||
): Reservoir.ReservoirArray<T>; // tslint:disable-line:no-unnecessary-generics
|
||||
|
||||
/*~ If you want to expose types from your module as well, you can
|
||||
*~ place them in this block. Often you will want to describe the
|
||||
*~ shape of the return type of the function; that type should
|
||||
*~ be declared in here, as this example shows.
|
||||
*/
|
||||
declare namespace Reservoir {
|
||||
interface ReservoirArray<T> extends Array<T> {
|
||||
/**
|
||||
* datum: one or more elements to consider for inclusion into the reservoir.
|
||||
* Returns the current length of the reservoir.
|
||||
*/
|
||||
pushSome(...datum: T[]): number;
|
||||
}
|
||||
}
|
||||
13
types/reservoir/reservoir-tests.ts
Normal file
13
types/reservoir/reservoir-tests.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import Reservoir = require('reservoir');
|
||||
|
||||
// $ExpectType ReservoirArray<number>
|
||||
const x = Reservoir<number>(1);
|
||||
|
||||
// $ExpectType number
|
||||
x.pushSome(10, 20, 30, 40);
|
||||
|
||||
// $ExpectType number
|
||||
x[0];
|
||||
|
||||
// $ExpectType number
|
||||
x.length;
|
||||
24
types/reservoir/tsconfig.json
Normal file
24
types/reservoir/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"reservoir-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/reservoir/tslint.json
Normal file
1
types/reservoir/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user