Closed
Description
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));
}