Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS1243: 'async' modifier cannot be used with 'abstract' modifier

In my project, I was using [email protected] and it was working fine, but now I updated its version to latest [email protected] and it is giving me a lot of errors. I am unable to find anything in documentations and not getting any Idea how to resolve this issue.

here is my code:

abstract class SystemValidator {

    constructor() {}

    abstract async validate(addr:Addr):Promise<[boolean, Addr[], SystemValidationErrors]>

}

This is giving me error:

error TS1243: 'async' modifier cannot be used with 'abstract' modifier.

Any idea to resolve this issue?? Should I remove aync from here??

like image 602
Naila Akbar Avatar asked Dec 18 '20 10:12

Naila Akbar


1 Answers

Yes you should remove async.

You should not force to use async to the class that implements it. There are other ways to return a Promise, not just async.

Edit:

Since it is not clear for some people why the async is not important. Here a couple of ways to return a promise:

async function iAmAsync(): Promise<boolean>{
    return false;
}

function iAmNotAsync(): Promise<boolean>{
 return new Promise(resolve => resolve(false));
}

function iAmAlsoNotAsync(): Promise<boolean>{
 return new Observable().pipe(first()).toPromise();
}

iAmAsync().then();
iAmNotAsync().then();

Playground Link

like image 123
distante Avatar answered Nov 12 '22 01:11

distante