// tslint:disable-next-line:no-floating-promises
async function asyncFunction() { ... }
asyncFunction(); // no error for this function
Could it be possible?
Use the void keyword when calling the function to indicate that you are not interested in the returned value:
void asyncFunction();
I never knew about void technique. 馃憤
However, it seems like it's not different with this.
// tslint:disable-next-line:no-floating-promises
asyncFunction();
You're right, disabling the rule for that line has the same effect.
There's a reason I suggested void. There's an open issue (and a PR https://github.com/Microsoft/TypeScript/pull/15195) for the typescript compiler to disallow floating promises in async functions. For example:
async function foo() {
asyncFunction(); // will result in an error
}
To avoid this error, the proposed workaround is to add the void keyword https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
async function foo() {
void asyncFunction(); // no error
}
I got it. thank you for the information.
There will be new compiler options on async/await, and it'll be better to use them in the future.
Most helpful comment
Use the
voidkeyword when calling the function to indicate that you are not interested in the returned value: