Add more tsdoc comments
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
/** Promise type with strongly typed error */
|
||||
export type CustomPromise<T, E> = Promise<T> & {
|
||||
__errorType: E
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Promise with strongly typed error
|
||||
* @param executor - Promise executor function
|
||||
* @returns Promise with typed error
|
||||
*/
|
||||
export function makePromise<T, E>(
|
||||
executor: (
|
||||
resolve: (value: T | PromiseLike<T>) => void,
|
||||
@@ -11,11 +17,16 @@ export function makePromise<T, E>(
|
||||
return new Promise(executor) as CustomPromise<T, E>
|
||||
}
|
||||
|
||||
/** Promise with exposed resolve/reject functions and typed error */
|
||||
export type Deferred<T, E = T> = CustomPromise<T, E> & {
|
||||
resolve: (arg: T) => void
|
||||
reject: (arg: E) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Deferred promise
|
||||
* @returns Promise with resolve/reject methods exposed
|
||||
*/
|
||||
export const defer = <T, E = T>(): Deferred<T, E> => {
|
||||
let resolve, reject
|
||||
const p = makePromise((resolve_, reject_) => {
|
||||
|
||||
Reference in New Issue
Block a user