diff --git a/types/flushable/flushable-tests.ts b/types/flushable/flushable-tests.ts new file mode 100644 index 0000000000..3d4bf565dc --- /dev/null +++ b/types/flushable/flushable-tests.ts @@ -0,0 +1,20 @@ +/** + * The usage example is taken directly + * from the package's README + */ + +import flushable from 'flushable'; + +// prints a message to the console after 1 second +const operation = flushable(flushed => { + const result = `I completed ${flushed ? 'early' : 'on time'}`; +}, 1000); + +// true if the callback has not been executed +operation.pending(); + +// stops the callback from being executed +operation.cancel(); + +// immediately executes the callback +operation.flush(); diff --git a/types/flushable/index.d.ts b/types/flushable/index.d.ts new file mode 100644 index 0000000000..eb3a08a214 --- /dev/null +++ b/types/flushable/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for flushable 1.0 +// Project: https://github.com/petegleeson/flushable#readme +// Definitions by: Parth Mehta +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type FlushableOnCompleteHandler = (flushed: boolean) => any; + +export interface FlushableOperation { + /** Returns whether or not the callback has been executed */ + pending: () => boolean; + /** Stops the callback from being executed */ + cancel: () => void; + /** Immediately executes the callback */ + flush: () => void; +} + +export default function flushable( + onComplete: FlushableOnCompleteHandler, + delay: number +): FlushableOperation; diff --git a/types/flushable/tsconfig.json b/types/flushable/tsconfig.json new file mode 100644 index 0000000000..27b5900f3e --- /dev/null +++ b/types/flushable/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "flushable-tests.ts"] +} diff --git a/types/flushable/tslint.json b/types/flushable/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/flushable/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }