Argument of type ‘HttpStatus’ is not assignable to parameter of type ‘(resolve: (value?: {} | Thenable) => void, reject: (reason?: any) => void) => any’. Type ‘HttpStatus’ provides no match for the signature ‘(resolve: (value?: {} | Thenable) => void, reject: (reason?: any) => void): any’.


Two way to resolved this problem:

Change index.d.ts

function resolve<T>(value?: T | Thenable<T>): Promise<T>;

This is a bad type definition. It makes the claim that for any type T, you can call the function with 0 arguments, and get a promise that resolves to T. Which is:

  • generally not what one intends by calling Promise.resolve() with no arguments,
  • just plain wrong if --strictNullChecks is enabled (since undefined will generally not be a member of an arbitrary type T)

It should be written with overloading instead:

function resolve<T>(value: T | Thenable<T>): Promise<T>;
function resolve(): Promise<void>;


 

Second way

In TypeScript’s built-in Promise type definition you get from --target ES6, Promise.resolve() is already correctly typed as Promise<void>.

private setSingle<T extends BaseObj>(helper: BaseHelper<T>, data): Promise<T> {

if (data.length >0) {
data = (JSON.parse(JSON.stringify(data[0])) as T);
return helper.createObject(data);
}
const promise =new Promise<T>((resolve, reject) => {
resolve(new HttpStatus<T>(HttpStatus.NOT_FOUND, null));
});
return promise;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s