From 43fb24f4cd6844a882ba2130cfb9f7d5bc301bdb Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Tue, 24 Dec 2019 18:59:46 -0800 Subject: [PATCH] Drop unnecessary Object.assign from createResolvable() (#3548) --- cli/js/util.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cli/js/util.ts b/cli/js/util.ts index b046a34f48..4bffb2e8ce 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 = (value?: T | PromiseLike) => void; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type RejectFunction = (reason?: any) => void; + export interface ResolvableMethods { - resolve: (value?: T | PromiseLike) => void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - reject: (reason?: any) => void; + resolve: ResolveFunction; + reject: RejectFunction; } // @internal @@ -73,13 +76,15 @@ export type Resolvable = Promise & ResolvableMethods; // @internal export function createResolvable(): Resolvable { - let methods: ResolvableMethods; - const promise = new Promise((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; + let resolve: ResolveFunction; + let reject: RejectFunction; + const promise = new Promise((res, rej): void => { + resolve = res; + reject = rej; + }) as Resolvable; + promise.resolve = resolve!; + promise.reject = reject!; + return promise; } // @internal