Use typescript strict mode (#505)

This commit is contained in:
Kitson Kelly 2018-08-15 09:40:30 -07:00 committed by Ryan Dahl
parent 0ce7b6e870
commit 168d92f5d2
7 changed files with 96 additions and 58 deletions

View file

@ -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>;
}