From 809c9fe482eb8ac2183d649b4ded101b288ea912 Mon Sep 17 00:00:00 2001 From: Chris Atkin Date: Fri, 3 Jan 2020 00:55:32 +0000 Subject: [PATCH] Add types for knuth-shuffle (#41259) * Add types for knuth-shuffle This adds types for the [`knuth-shuffle`](https://www.npmjs.com/package/knuth-shuffle) package. * Correct return type to be same as passed array This corrects the return type for the `knuthShuffle` function, as it returns an array of the same type (specifically, the same array!), rather than `void`. * Correct tests --- types/knuth-shuffle/index.d.ts | 6 ++++++ types/knuth-shuffle/knuth-shuffle-tests.ts | 4 ++++ types/knuth-shuffle/tsconfig.json | 23 ++++++++++++++++++++++ types/knuth-shuffle/tslint.json | 1 + 4 files changed, 34 insertions(+) create mode 100644 types/knuth-shuffle/index.d.ts create mode 100644 types/knuth-shuffle/knuth-shuffle-tests.ts create mode 100644 types/knuth-shuffle/tsconfig.json create mode 100644 types/knuth-shuffle/tslint.json diff --git a/types/knuth-shuffle/index.d.ts b/types/knuth-shuffle/index.d.ts new file mode 100644 index 0000000000..e2c2e37123 --- /dev/null +++ b/types/knuth-shuffle/index.d.ts @@ -0,0 +1,6 @@ +// Type definitions for knuth-shuffle 1.0 +// Project: https://git.coolaj86.com/coolaj86/knuth-shuffle.js +// Definitions by: Chris Atkin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export function knuthShuffle(array: T[]): T[]; diff --git a/types/knuth-shuffle/knuth-shuffle-tests.ts b/types/knuth-shuffle/knuth-shuffle-tests.ts new file mode 100644 index 0000000000..7d5397d421 --- /dev/null +++ b/types/knuth-shuffle/knuth-shuffle-tests.ts @@ -0,0 +1,4 @@ +import { knuthShuffle } from "knuth-shuffle"; + +knuthShuffle([4, 8, 15, 16, 23, 42]); // $ExpectType number[] +knuthShuffle(['a', 'b', 'c', 'd']); // $ExpectType string[] diff --git a/types/knuth-shuffle/tsconfig.json b/types/knuth-shuffle/tsconfig.json new file mode 100644 index 0000000000..577c4d73ba --- /dev/null +++ b/types/knuth-shuffle/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "knuth-shuffle-tests.ts" + ] +} diff --git a/types/knuth-shuffle/tslint.json b/types/knuth-shuffle/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/knuth-shuffle/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }