diff --git a/types/debounce/debounce-tests.ts b/types/debounce/debounce-tests.ts index 14d7cab190..81924d2a28 100644 --- a/types/debounce/debounce-tests.ts +++ b/types/debounce/debounce-tests.ts @@ -1,13 +1,15 @@ - -import debounce from "debounce"; +import debounce = require("debounce"); const doThings = () => 1; -debounce(function(){ doThings(); })(); +debounce(doThings)(); -debounce(function(){ doThings(); }, 1000)(); +debounce(doThings, 1000)(); -debounce(function(a: string){ doThings(); }, 1000)("foo"); +debounce((a: string) => doThings, 1000)("foo"); // Immediate true should return the value const imm1: number = (debounce((x: number) => x * 2, 100, true))(2); + +const clearable = debounce(doThings); +clearable.clear(); diff --git a/types/debounce/index.d.ts b/types/debounce/index.d.ts index 43b1630689..09a9c82e38 100644 --- a/types/debounce/index.d.ts +++ b/types/debounce/index.d.ts @@ -1,10 +1,7 @@ -// Type definitions for compose-function +// Type definitions for debounce 1.0 // Project: https://github.com/component/debounce // Definitions by: Denis Sokolov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -// Overload on boolean constants would allow us to narrow further, -// but it is not implemented for TypeScript yet -declare function f(f: A, interval?: number, immediate?: boolean): A -export default f; +declare function debounce(f: A, interval?: number, immediate?: boolean): A & { clear(): void; }; +export = debounce; diff --git a/types/debounce/tslint.json b/types/debounce/tslint.json new file mode 100644 index 0000000000..5bc412fb1e --- /dev/null +++ b/types/debounce/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "ban-types": false + } +}