-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): generate types from jsdoc comments so ts projects also ha…
…ve the textual descriptions in addition to the type definitions
- Loading branch information
Showing
5 changed files
with
89 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @typedef {Object} PrecurringController | ||
* @property {() => void} start Starts the interval | ||
* @property {() => void} stop Stops the interval | ||
*/ | ||
/** | ||
* @template K | ||
* @typedef {Object} PrecurringOptions | ||
* @property {(...args: any[]) => Promise<K>} fn The function you want to repeatedly call, returning a Promise | ||
* @property {number} interval Time in ms representing the time span between the last Promise settling and the next one firing | ||
* @property {number} [timeout] The maximum amount of time in ms which the promise is allowed to take | ||
* @property {(value: K) => any} onSuccess The success callback | ||
* @property {(reason: K | Error) => any} onError The error callback | ||
*/ | ||
/** | ||
* @function | ||
* @template K | ||
* | ||
* Creates a new instance | ||
* @param {PrecurringOptions<K>} options An options object | ||
* | ||
* @returns {PrecurringController} | ||
*/ | ||
export default function _default<K>({ fn, interval, timeout, onSuccess, onError }: PrecurringOptions<K>): PrecurringController; | ||
export type PrecurringController = { | ||
/** | ||
* Starts the interval | ||
*/ | ||
start: () => void; | ||
/** | ||
* Stops the interval | ||
*/ | ||
stop: () => void; | ||
}; | ||
export type PrecurringOptions<K> = { | ||
/** | ||
* The function you want to repeatedly call, returning a Promise | ||
*/ | ||
fn: (...args: any[]) => Promise<K>; | ||
/** | ||
* Time in ms representing the time span between the last Promise settling and the next one firing | ||
*/ | ||
interval: number; | ||
/** | ||
* The maximum amount of time in ms which the promise is allowed to take | ||
*/ | ||
timeout?: number; | ||
/** | ||
* The success callback | ||
*/ | ||
onSuccess: (value: K) => any; | ||
/** | ||
* The error callback | ||
*/ | ||
onError: (reason: K | Error) => any; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import precurring from '.'; | ||
|
||
precurring({ | ||
fn: () => fetch('/'), | ||
interval: 1000, | ||
onError: (reason) => console.log(reason), | ||
onSuccess: (val) => console.log(val), | ||
}); |
This file was deleted.
Oops, something went wrong.