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
This commit is contained in:
Chris Atkin 2020-01-03 00:55:32 +00:00 committed by Ryan Cavanaugh
parent fe47c041d5
commit 809c9fe482
4 changed files with 34 additions and 0 deletions

6
types/knuth-shuffle/index.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
// Type definitions for knuth-shuffle 1.0
// Project: https://git.coolaj86.com/coolaj86/knuth-shuffle.js
// Definitions by: Chris Atkin <https://github.com/atkinchris>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function knuthShuffle<T>(array: T[]): T[];

View File

@ -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[]

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }