diff --git a/types/weighted-random-object/index.d.ts b/types/weighted-random-object/index.d.ts new file mode 100644 index 0000000000..ba13081922 --- /dev/null +++ b/types/weighted-random-object/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for weighted-random-object 1.0 +// Project: https://github.com/misund/weighted-random-object +// Definitions by: mike castleman +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.7 + +interface Weighted { + weight: number; +} + +declare function weightedRandomObject(objects: ReadonlyArray): T; + +export = weightedRandomObject; diff --git a/types/weighted-random-object/tsconfig.json b/types/weighted-random-object/tsconfig.json new file mode 100644 index 0000000000..dfc16adb0e --- /dev/null +++ b/types/weighted-random-object/tsconfig.json @@ -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" + ] +} diff --git a/types/weighted-random-object/tslint.json b/types/weighted-random-object/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/weighted-random-object/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/weighted-random-object/weighted-random-object-tests.ts b/types/weighted-random-object/weighted-random-object-tests.ts new file mode 100644 index 0000000000..99fd0a6d7e --- /dev/null +++ b/types/weighted-random-object/weighted-random-object-tests.ts @@ -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