mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
add types for weighted-random-object (#36885)
This commit is contained in:
parent
fc8781c262
commit
670e84438c
14
types/weighted-random-object/index.d.ts
vendored
Normal file
14
types/weighted-random-object/index.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
// Type definitions for weighted-random-object 1.0
|
||||
// Project: https://github.com/misund/weighted-random-object
|
||||
// Definitions by: mike castleman <https://github.com/mlc>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// TypeScript Version: 2.7
|
||||
|
||||
interface Weighted {
|
||||
weight: number;
|
||||
}
|
||||
|
||||
declare function weightedRandomObject<T extends Weighted>(objects: ReadonlyArray<T>): T;
|
||||
|
||||
export = weightedRandomObject;
|
||||
24
types/weighted-random-object/tsconfig.json
Normal file
24
types/weighted-random-object/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",
|
||||
"weighted-random-object-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/weighted-random-object/tslint.json
Normal file
1
types/weighted-random-object/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
12
types/weighted-random-object/weighted-random-object-tests.ts
Normal file
12
types/weighted-random-object/weighted-random-object-tests.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import weightedRandomObject from 'weighted-random-object';
|
||||
|
||||
interface MyObject {
|
||||
data: string;
|
||||
weight: number;
|
||||
}
|
||||
|
||||
const objs: MyObject[] = [{ data: 'a', weight: 7 }, { data: 'b', weight: 5 }];
|
||||
|
||||
weightedRandomObject(objs); // $ExpectType MyObject
|
||||
|
||||
weightedRandomObject([{ f: 5, weight: 1 }, { f: 9, weight: 2 }]).f; // $ExpectType number
|
||||
Loading…
Reference in New Issue
Block a user