I'm doing some basic asynchronous operations using async/await
in TypeScript but TSLint is throwing mysterious error messages for these two functions below. Has anyone encountered these errors before? On the error output the governing rule is not mentioned, so I don't understand what's causing these. Any ideas would be greatly appreciated.
The main request:
import * as rp from 'request-promise'
export function getRequest(address: rp.Options): rp.RequestPromise {
return rp(address)
}
Exported async function:
export async function getStatus(message: Message) {
try {
const res = await getRequest(address)
if (res.ready) {
message.reply('...')
} else {
message.reply('...')
}
} catch (err) {
message.reply(err)
}
}
This gets: Promises must be handled appropriately
and await of non-Promise
for line #3.
The simple function that uses this export is:
client.on('message', message => {
if (message.content === 'green') {
getStatus(message)
}
})
This also gets Promises must be handled appropriately
.
Additional information:
Even though the error message doesn't mention it, this seems to be the governing rule for Promises must be handled appropriately
:
https://palantir.github.io/tslint/rules/no-floating-promises/
And this Issue mentions await of non-Promise
:
https://github.com/palantir/tslint/issues/2661
rp
. So I used this:export function getRequest(address: rp.Options): rp.RequestPromise { return rp(address) }
This satisfies the IDE but I'm still getting exactly the same errors in the initial post. – Juryrig