From 7972e20c7dcf7a6324ee821507f4401a4c6b4b24 Mon Sep 17 00:00:00 2001 From: Parth Mehta Date: Sun, 16 Dec 2018 21:22:28 +1100 Subject: [PATCH 1/4] :sparkles: added types --- types/flushable/index.d.ts | 23 +++++++++++++++++++++++ types/flushable/tsconfig.json | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 types/flushable/index.d.ts create mode 100644 types/flushable/tsconfig.json diff --git a/types/flushable/index.d.ts b/types/flushable/index.d.ts new file mode 100644 index 0000000000..3e0495c7fe --- /dev/null +++ b/types/flushable/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for flushable 1.0.0 +// Project: https://github.com/petegleeson/flushable +// Definitions by: Parth Mehta +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +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; +} + +declare module 'flushable' { + 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..30c42668dd --- /dev/null +++ b/types/flushable/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6", "dom"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts"] +} From f9f74af90ed31afb0f70cabb5281b906e32c956d Mon Sep 17 00:00:00 2001 From: Parth Mehta Date: Sun, 16 Dec 2018 21:36:52 +1100 Subject: [PATCH 2/4] :bug: fixed structure according to guidelines in the DefinitelyTyped's README --- types/flushable/flushable-tests.ts | 20 ++++++++++++++++++++ types/flushable/index.d.ts | 5 ++--- types/flushable/tsconfig.json | 7 +++---- types/flushable/tslint.json | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 types/flushable/flushable-tests.ts create mode 100644 types/flushable/tslint.json 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 index 3e0495c7fe..0028d81680 100644 --- a/types/flushable/index.d.ts +++ b/types/flushable/index.d.ts @@ -1,8 +1,7 @@ -// Type definitions for flushable 1.0.0 -// Project: https://github.com/petegleeson/flushable +// Type definitions for flushable 1.0 +// Project: https://github.com/petegleeson/flushable#readme // Definitions by: Parth Mehta // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.0 export type FlushableOnCompleteHandler = (flushed: boolean) => any; diff --git a/types/flushable/tsconfig.json b/types/flushable/tsconfig.json index 30c42668dd..b55678ce92 100644 --- a/types/flushable/tsconfig.json +++ b/types/flushable/tsconfig.json @@ -1,16 +1,15 @@ { "compilerOptions": { "module": "commonjs", - "lib": ["es6", "dom"], + "lib": ["es6"], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, - "strictFunctionTypes": true, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, - "files": ["index.d.ts"] + "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" } From 67962ba5f31709671e481704d9fd5ebc107441f2 Mon Sep 17 00:00:00 2001 From: Parth Mehta Date: Sun, 16 Dec 2018 21:45:22 +1100 Subject: [PATCH 3/4] :bug: added strictFunctionTypes --- types/flushable/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/flushable/tsconfig.json b/types/flushable/tsconfig.json index b55678ce92..27b5900f3e 100644 --- a/types/flushable/tsconfig.json +++ b/types/flushable/tsconfig.json @@ -5,6 +5,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": ["../"], "types": [], From 562cebfeb038a4ff3cfcb4e9acc1a3b7ddd9594e Mon Sep 17 00:00:00 2001 From: Parth Mehta Date: Sun, 16 Dec 2018 21:46:59 +1100 Subject: [PATCH 4/4] :bug: added contents directly instead of having a module declaration --- types/flushable/index.d.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/types/flushable/index.d.ts b/types/flushable/index.d.ts index 0028d81680..eb3a08a214 100644 --- a/types/flushable/index.d.ts +++ b/types/flushable/index.d.ts @@ -14,9 +14,7 @@ export interface FlushableOperation { flush: () => void; } -declare module 'flushable' { - export default function flushable( - onComplete: FlushableOnCompleteHandler, - delay: number - ): FlushableOperation; -} +export default function flushable( + onComplete: FlushableOnCompleteHandler, + delay: number +): FlushableOperation;