jessehouwing
jessehouwing

Reputation: 114711

TsLint complains about calling top level async method

I've configured TsLint to warn for unhandled promises:

{
    "rules": {
        "no-floating-promises": [
          true,
          "Promise",
          "Q.Promise" 
        ],
    }
}

The code follows the standard template for build tasks for vsts:

async function run() {
  try {
      ...
  } catch (err) {
      tl.setResult(tl.TaskResult.Failed, err.message);
  }
}

run(); // tslint complains here...

TsLint now complains that the promise is unhandled, but I can't add await before run... I don't want to mix run with .then as it's introducing another async paradigm...

ERROR: C:/Users/JesseHouwing/Source/Repos/....ts[16, 5]: Promises must be handled appropriately

These tasks are executed in Node, not awaiting the run method, it's working fine... Can I safely suppress this? Is there a better way of doing this?

Upvotes: 2

Views: 610

Answers (1)

jessehouwing
jessehouwing

Reputation: 114711

It seems that I can safely suppress the value by using:

async function run() {
  try {
      ...
  } catch (err) {
      tl.setResult(tl.TaskResult.Failed, err.message);
  }
}

void run(); // tslint no longer complains here and it's explicit :)

Inserting void in front of the top level run method seems to solve this.

Upvotes: 4

Related Questions