Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Suppressing no-floating-promises on specific function #3056

Closed
rokoroku opened this issue Jul 19, 2017 · 4 comments
Closed

Suppressing no-floating-promises on specific function #3056

rokoroku opened this issue Jul 19, 2017 · 4 comments

Comments

@rokoroku
Copy link

TypeScript code being linted

// tslint:disable-next-line:no-floating-promises
async function asyncFunction() { ... }

asyncFunction(); // no error for this function

Could it be possible?

@ajafff
Copy link
Contributor

ajafff commented Jul 19, 2017

Use the void keyword when calling the function to indicate that you are not interested in the returned value:

void asyncFunction();

@rokoroku
Copy link
Author

I never knew about void technique. 👍
However, it seems like it's not different with this.

// tslint:disable-next-line:no-floating-promises
asyncFunction();

@ajafff
Copy link
Contributor

ajafff commented Jul 19, 2017

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 microsoft/TypeScript#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 microsoft/TypeScript#13376 (comment)

async function foo() {
    void asyncFunction(); // no error
}

@rokoroku
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants