Create definition for just-throttle (#38707)

* Create definition for just-throttle

* Use more specific URL for the project

* Improve comments in tests slightly
This commit is contained in:
Dominik Rowicki 2019-10-02 22:56:23 +02:00 committed by Ryan Cavanaugh
parent 115ed66c06
commit 6d7624e50f
4 changed files with 45 additions and 0 deletions

10
types/just-throttle/index.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
// Type definitions for just-throttle 1.1
// Project: https://github.com/angus-c/just/tree/master/packages/function-throttle
// Definitions by: Dominik Rowicki <https://github.com/papermana>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
declare function throttle(fn: (...args: unknown[]) => unknown, interval: number, callFirst?: false): () => void;
declare function throttle<T>(fn: T, interval: number, callFirst?: true): T;
export = throttle;

View File

@ -0,0 +1,11 @@
import throttle = require('just-throttle');
// returns a function that sets an interval but doesn't do anything else by
// default
throttle(() => 'foo', 200); // $ExpectType () => void
throttle(() => 'foo', 200, false); // $ExpectType () => void
// if third argument is true, the returned function will immediately apply the
// callback when called
throttle(() => 'foo', 200, true); // $ExpectType () => string
throttle((foo: string) => 42, 200, true); // $ExpectType (foo: string) => number

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",
"just-throttle-tests.ts"
]
}

View File

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