From 5d9f20280fee623b11f6ed09765e7a205fafdc4f Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Thu, 9 Aug 2018 15:06:30 +0300 Subject: [PATCH 1/7] Add typescript typings --- index.d.ts | 10 ++++++++++ package.json | 1 + 2 files changed, 11 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..580c23e --- /dev/null +++ b/index.d.ts @@ -0,0 +1,10 @@ +interface ClearablePromise extends Promise { + clear (): void +} + +declare const delay: { + (ms: number, value?: T): ClearablePromise + reject(ms: number, reason?: any): ClearablePromise +} + +export = delay diff --git a/package.json b/package.json index 5e56991..40160fd 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "files": [ "index.js" ], + "typings": "index.d.ts", "keywords": [ "promise", "resolve", From d01ed3aa54c1081c458933aaa9e567793dbc37d8 Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Mon, 20 Aug 2018 10:41:49 +0300 Subject: [PATCH 2/7] Add tsdoc comments and default export --- index.d.ts | 31 ++++++++++++++++++++++++++----- index.js | 6 ++++-- package.json | 4 ++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 580c23e..06757f5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,10 +1,31 @@ interface ClearablePromise extends Promise { - clear (): void + /** + * Clears the delay and settles the promise. + * + * @memberof ClearablePromise + */ + clear(): void; } declare const delay: { - (ms: number, value?: T): ClearablePromise - reject(ms: number, reason?: any): ClearablePromise -} + /** + * Create a promise which resolves after the specified `milliseconds`. + * Optionally pass a `value` to resolve. + * + * @param {number} milliseconds Milliseconds to delay the promise. + * @param {T} [value] Value to resolve in the returned promise. + * @returns {ClearablePromise} a promise which resolves after the specified `milliseconds` + */ + (milliseconds: number, value?: T): ClearablePromise; + /** + * Create a promise which rejects after the specified `milliseconds`. + * Optionally pass a `reason` to reject. + * + * @param {number} milliseconds Milliseconds to delay the promise. + * @param {*} [reason] Value to reject in the returned promise. + * @returns {ClearablePromise} a promise which rejects after the specified `milliseconds`. + */ + reject(milliseconds: number, reason?: any): ClearablePromise; +}; -export = delay +export default delay; diff --git a/index.js b/index.js index 905c856..883da08 100644 --- a/index.js +++ b/index.js @@ -20,5 +20,7 @@ const createDelay = willResolve => (ms, value) => { return delayPromise; }; -module.exports = createDelay(true); -module.exports.reject = createDelay(false); +const delay = createDelay(true); +delay.reject = createDelay(false); +module.exports = delay; +module.exports.default = delay; diff --git a/package.json b/package.json index 40160fd..febebb0 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,9 @@ "test": "xo && ava" }, "files": [ - "index.js" + "index.js", + "index.d.ts" ], - "typings": "index.d.ts", "keywords": [ "promise", "resolve", From d5a7a445f68545c7f6f875c8f2ffbd7256fd3b36 Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Mon, 20 Aug 2018 10:45:02 +0300 Subject: [PATCH 3/7] Fix code style --- index.d.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index 06757f5..9611e96 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,7 +4,7 @@ interface ClearablePromise extends Promise { * * @memberof ClearablePromise */ - clear(): void; + clear(): void; } declare const delay: { @@ -15,17 +15,18 @@ declare const delay: { * @param {number} milliseconds Milliseconds to delay the promise. * @param {T} [value] Value to resolve in the returned promise. * @returns {ClearablePromise} a promise which resolves after the specified `milliseconds` - */ + */ (milliseconds: number, value?: T): ClearablePromise; - /** - * Create a promise which rejects after the specified `milliseconds`. - * Optionally pass a `reason` to reject. - * - * @param {number} milliseconds Milliseconds to delay the promise. - * @param {*} [reason] Value to reject in the returned promise. - * @returns {ClearablePromise} a promise which rejects after the specified `milliseconds`. - */ - reject(milliseconds: number, reason?: any): ClearablePromise; + + /** + * Create a promise which rejects after the specified `milliseconds`. + * Optionally pass a `reason` to reject. + * + * @param {number} milliseconds Milliseconds to delay the promise. + * @param {*} [reason] Value to reject in the returned promise. + * @returns {ClearablePromise} a promise which rejects after the specified `milliseconds`. + */ + reject(milliseconds: number, reason?: any): ClearablePromise; }; export default delay; From 0204f6e740834a4f2d69e247a0fe2f04b8ff1e7a Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Mon, 20 Aug 2018 10:49:22 +0300 Subject: [PATCH 4/7] Add todo notice about reason type --- index.d.ts | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9611e96..71cc467 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,32 +1,33 @@ interface ClearablePromise extends Promise { - /** - * Clears the delay and settles the promise. - * - * @memberof ClearablePromise - */ - clear(): void; + /** + * Clears the delay and settles the promise. + * + * @memberof ClearablePromise + */ + clear(): void; } declare const delay: { - /** - * Create a promise which resolves after the specified `milliseconds`. - * Optionally pass a `value` to resolve. - * - * @param {number} milliseconds Milliseconds to delay the promise. - * @param {T} [value] Value to resolve in the returned promise. - * @returns {ClearablePromise} a promise which resolves after the specified `milliseconds` - */ - (milliseconds: number, value?: T): ClearablePromise; - - /** - * Create a promise which rejects after the specified `milliseconds`. - * Optionally pass a `reason` to reject. - * - * @param {number} milliseconds Milliseconds to delay the promise. - * @param {*} [reason] Value to reject in the returned promise. - * @returns {ClearablePromise} a promise which rejects after the specified `milliseconds`. - */ - reject(milliseconds: number, reason?: any): ClearablePromise; + /** + * Create a promise which resolves after the specified `milliseconds`. + * Optionally pass a `value` to resolve. + * + * @param {number} milliseconds Milliseconds to delay the promise. + * @param {T} [value] Value to resolve in the returned promise. + * @returns {ClearablePromise} a promise which resolves after the specified `milliseconds` + */ + (milliseconds: number, value?: T): ClearablePromise; + + /** + * Create a promise which rejects after the specified `milliseconds`. + * Optionally pass a `reason` to reject. + * + * @param {number} milliseconds Milliseconds to delay the promise. + * @param {*} [reason] Value to reject in the returned promise. + * @returns {ClearablePromise} a promise which rejects after the specified `milliseconds`. + */ + // TODO: Allow providing reason type after https://github.com/Microsoft/TypeScript/issues/5413 will be resolved. + reject(milliseconds: number, reason?: any): ClearablePromise; }; export default delay; From b5f8fd28a245b44732dbee45a84f40ae741f2bae Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Mon, 20 Aug 2018 11:26:42 +0300 Subject: [PATCH 5/7] Remove type definitions from tsdoc comments --- index.d.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 71cc467..bee0651 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,6 @@ interface ClearablePromise extends Promise { /** * Clears the delay and settles the promise. - * - * @memberof ClearablePromise */ clear(): void; } @@ -12,9 +10,9 @@ declare const delay: { * Create a promise which resolves after the specified `milliseconds`. * Optionally pass a `value` to resolve. * - * @param {number} milliseconds Milliseconds to delay the promise. - * @param {T} [value] Value to resolve in the returned promise. - * @returns {ClearablePromise} a promise which resolves after the specified `milliseconds` + * @param milliseconds - Milliseconds to delay the promise. + * @param value - Value to resolve in the returned promise. + * @returns A promise which resolves after the specified `milliseconds`. */ (milliseconds: number, value?: T): ClearablePromise; @@ -22,9 +20,9 @@ declare const delay: { * Create a promise which rejects after the specified `milliseconds`. * Optionally pass a `reason` to reject. * - * @param {number} milliseconds Milliseconds to delay the promise. - * @param {*} [reason] Value to reject in the returned promise. - * @returns {ClearablePromise} a promise which rejects after the specified `milliseconds`. + * @param milliseconds - Milliseconds to delay the promise. + * @param reason - Value to reject in the returned promise. + * @returns A promise which rejects after the specified `milliseconds`. */ // TODO: Allow providing reason type after https://github.com/Microsoft/TypeScript/issues/5413 will be resolved. reject(milliseconds: number, reason?: any): ClearablePromise; From 1a17beeef848e85cea23c32d3a603811472f635e Mon Sep 17 00:00:00 2001 From: Dmitry Korolev Date: Mon, 20 Aug 2018 18:01:21 +0300 Subject: [PATCH 6/7] Split delay type definition into two overloads --- index.d.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index bee0651..b66538c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,6 +6,15 @@ interface ClearablePromise extends Promise { } declare const delay: { + /** + * Create a promise which resolves after the specified `milliseconds`. + * Optionally pass a `value` to resolve. + * + * @param milliseconds - Milliseconds to delay the promise. + * @returns A promise which resolves after the specified `milliseconds`. + */ + (milliseconds: number): ClearablePromise; + /** * Create a promise which resolves after the specified `milliseconds`. * Optionally pass a `value` to resolve. @@ -14,7 +23,7 @@ declare const delay: { * @param value - Value to resolve in the returned promise. * @returns A promise which resolves after the specified `milliseconds`. */ - (milliseconds: number, value?: T): ClearablePromise; + (milliseconds: number, value: T): ClearablePromise; /** * Create a promise which rejects after the specified `milliseconds`. From 4a197ec210fb38b40e9af1a4573896b31ebf8429 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 21 Aug 2018 00:50:57 +0700 Subject: [PATCH 7/7] Update index.d.ts --- index.d.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index b66538c..0fcb115 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,7 +8,6 @@ interface ClearablePromise extends Promise { declare const delay: { /** * Create a promise which resolves after the specified `milliseconds`. - * Optionally pass a `value` to resolve. * * @param milliseconds - Milliseconds to delay the promise. * @returns A promise which resolves after the specified `milliseconds`. @@ -17,7 +16,6 @@ declare const delay: { /** * Create a promise which resolves after the specified `milliseconds`. - * Optionally pass a `value` to resolve. * * @param milliseconds - Milliseconds to delay the promise. * @param value - Value to resolve in the returned promise. @@ -27,7 +25,6 @@ declare const delay: { /** * Create a promise which rejects after the specified `milliseconds`. - * Optionally pass a `reason` to reject. * * @param milliseconds - Milliseconds to delay the promise. * @param reason - Value to reject in the returned promise.