mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[debounce-fn] Add types
This commit is contained in:
10
types/debounce-fn/debounce-fn-tests.ts
Normal file
10
types/debounce-fn/debounce-fn-tests.ts
Normal 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
34
types/debounce-fn/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
23
types/debounce-fn/tsconfig.json
Normal file
23
types/debounce-fn/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/debounce-fn/tslint.json
Normal file
1
types/debounce-fn/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user