Merge pull request #30162 from azizhk/just-debounce-it

Add definitions for just-debounce-it
This commit is contained in:
Daniel Rosenwasser
2018-11-01 16:03:02 -07:00
committed by GitHub
4 changed files with 82 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
// Type definitions for just-debounce-it 1.1
// Project: https://github.com/angus-c/just#readme
// Definitions by: Aziz Khambati <https://github.com/azizhk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any ? A : never;
/*~ This declaration specifies that the function
*~ is the exported object from the file
*/
export = debounce;
declare function debounce<T extends Function>(
fn: T,
wait?: 0,
callFirst?: boolean
): T;
declare function debounce<T extends Function>(
fn: T,
wait: number,
callFirst: true
): T;
declare function debounce<T extends Function>(
fn: T,
wait: number,
callFirst?: false
): (...args: ArgumentTypes<T>) => void;
@@ -0,0 +1,23 @@
import debounce = require("just-debounce-it");
const doThings = () => 1;
const num: number = debounce(doThings)();
const num2: number = debounce(doThings, 0)();
const num3: number = debounce(doThings, 0, true)();
const num4: number = debounce(doThings, 0, false)();
const num5: number = debounce(doThings, 1000, true)();
// $ExpectType void
debounce(doThings, 1000)();
const exclaim = (a: string) => a + '!';
const str: string = debounce(exclaim)('hey');
const str2: string = debounce(exclaim, 0)('hi');
const str3: string = debounce(exclaim, 0, true)('hi');
const str4: string = debounce(exclaim, 0, false)('hi');
const str5: string = debounce(exclaim, 1000, true)('hooray');
// $ExpectType void
debounce(exclaim, 1000)('hello');
+23
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-debounce-it-tests.ts"
]
}
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false
}
}