diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-12-24 18:59:46 -0800 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-12-24 21:59:46 -0500 |
commit | 43fb24f4cd6844a882ba2130cfb9f7d5bc301bdb (patch) | |
tree | 0a26ddb1d681b6eb844dd0f79f68d5543d9261be /cli/js | |
parent | 3bb15ceaeaf5cd349afcb2e2d43374efd420aaef (diff) |
Drop unnecessary Object.assign from createResolvable() (#3548)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/util.ts | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/cli/js/util.ts b/cli/js/util.ts index b046a34f4..4bffb2e8c 100644 --- a/cli/js/util.ts +++ b/cli/js/util.ts @@ -62,10 +62,13 @@ export function arrayToStr(ui8: Uint8Array): string { * @internal */ +export type ResolveFunction<T> = (value?: T | PromiseLike<T>) => void; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type RejectFunction = (reason?: any) => void; + export interface ResolvableMethods<T> { - resolve: (value?: T | PromiseLike<T>) => void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - reject: (reason?: any) => void; + resolve: ResolveFunction<T>; + reject: RejectFunction; } // @internal @@ -73,13 +76,15 @@ export type Resolvable<T> = Promise<T> & ResolvableMethods<T>; // @internal export function createResolvable<T>(): Resolvable<T> { - let methods: ResolvableMethods<T>; - const promise = new Promise<T>((resolve, reject): void => { - methods = { resolve, reject }; - }); - // TypeScript doesn't know that the Promise callback occurs synchronously - // therefore use of not null assertion (`!`) - return Object.assign(promise, methods!) as Resolvable<T>; + let resolve: ResolveFunction<T>; + let reject: RejectFunction; + const promise = new Promise<T>((res, rej): void => { + resolve = res; + reject = rej; + }) as Resolvable<T>; + promise.resolve = resolve!; + promise.reject = reject!; + return promise; } // @internal |