Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[no-floating-promises] feature: does-not-throw annotation #3192

Closed
@yury-s

Description

@yury-s

no-floating-promises rule currently supports to ways to suppress error: adding .catch to the promise and prepending void to the expression. In many cases it's known that returned Promise never throws and having to prepend all call sites with void just to suppress lint errors is tedious and impacts code readability. Rather than polluting all call sites with such annotations it'd be nice to have a marker on the async method/field telling lint that it never throws. Something like this:

class StringProvider {
  private _stringPromise: Promise<string>;
  _resolve: (s: string) => void = () => {};
  constructor() {
    this._stringPromise = new Promise(r => this._resolve = r);
  }

  // tslint:does-not-throw
  async string(): Promise<string> {
    return await this._stringPromise;
  }
}

function runWithString(provider: StringProvider) {
   provider.string().then(s => console.log('ready: ' + s));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions