mirror of
https://github.com/denoland/deno.git
synced 2025-08-02 18:12:39 +00:00
Use typescript strict mode (#505)
This commit is contained in:
parent
0ce7b6e870
commit
168d92f5d2
7 changed files with 96 additions and 58 deletions
11
js/util.ts
11
js/util.ts
|
@ -49,15 +49,20 @@ export function arrayToStr(ui8: Uint8Array): string {
|
|||
// produces broken code when targeting ES5 code.
|
||||
// See https://github.com/Microsoft/TypeScript/issues/15202
|
||||
// At the time of writing, the github issue is closed but the problem remains.
|
||||
export interface Resolvable<T> extends Promise<T> {
|
||||
export interface ResolvableMethods<T> {
|
||||
resolve: (value?: T | PromiseLike<T>) => void;
|
||||
// tslint:disable-next-line:no-any
|
||||
reject: (reason?: any) => void;
|
||||
}
|
||||
|
||||
type Resolvable<T> = Promise<T> & ResolvableMethods<T>;
|
||||
|
||||
export function createResolvable<T>(): Resolvable<T> {
|
||||
let methods;
|
||||
let methods: ResolvableMethods<T>;
|
||||
const promise = new Promise<T>((resolve, reject) => {
|
||||
methods = { resolve, reject };
|
||||
});
|
||||
return Object.assign(promise, methods) as Resolvable<T>;
|
||||
// TypeScript doesn't know that the Promise callback occurs synchronously
|
||||
// therefore use of not null assertion (`!`)
|
||||
return Object.assign(promise, methods!) as Resolvable<T>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue