[debounce-fn] Add types

This commit is contained in:
Dimitri Benin
2019-01-13 02:21:23 +01:00
parent 3a69de74e2
commit 16e70dce12
4 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
import debounceFn = require('debounce-fn');
const debounced = debounceFn((s: string) => true);
debounced; // $ExpectType ((s: string) => boolean | undefined) & { cancel(): void; }
debounceFn((s: string) => true);
debounceFn((s: string) => true, { wait: 100 });
debounceFn((s: string) => true, { immediate: true });
debounced.cancel();

34
types/debounce-fn/index.d.ts vendored Normal file
View File

@@ -0,0 +1,34 @@
// Type definitions for debounce-fn 1.0
// Project: https://github.com/sindresorhus/debounce-fn#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
export = debounce;
/**
* Returns a debounced function that delays calling the `input` function until after `wait` milliseconds
* have elapsed since the last time the debounced function was called.
*
* It comes with a `.cancel()` method to cancel any scheduled `input` function calls.
*/
declare function debounce<TArgs extends any[], TResult>(
input: (...args: TArgs) => TResult,
options?: debounce.Options
): ((...args: TArgs) => TResult | undefined) & { cancel(): void };
declare namespace debounce {
interface Options {
/**
* Time to wait until the `input` function is called.
* @default 0
*/
wait?: number;
/**
* Trigger the function on the leading edge instead of the trailing edge of the `wait` interval.
* For example, can be useful for preventing accidental double-clicks on a "submit" button
* from firing a second time.
*/
immediate?: boolean;
}
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"debounce-fn-tests.ts"
]
}

View File

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