JeB
JeB

Reputation: 12133

void before promise syntax

What is the actual impact of putting void before promise?

async function doAsyncStuff(){
...
}

function nonAsyncFunction(){
  void doAsyncStuff();
}

I couldn't find any official documentation for this, but it must be doing something as it resolves no-floating-promises TSLint error.

Upvotes: 29

Views: 15648

Answers (1)

Quentin
Quentin

Reputation: 943561

void is an operator that accepts a value on the Right-Hand Side and evaluates as undefined.

It resolves no-floating-promises because it does something (or rather, explicitly nothing) with the promise.

Upvotes: 34

Related Questions