Can't define onTeardown/onChange event handlers as non-async
AlexAegis opened this issue · 0 comments
AlexAegis commented
onTeardown and OnChangeEventHandler requires you to return a Promise. If you have an eventHandler that doesn't need to be async, @typescript-eslint/require-await
will make it unnecessarily ugly, like wrapping it in a Promise
, awaiting a noop, disabling the lint rule for one line.
Expected Behavior
This, to be fine
onTeardown: (): void => {
if (spawnedOnFirstBuild) {
spawnedOnFirstBuild.kill();
}
}
Current Behavior
// Async method 'onTeardown' has no 'await' expression.eslint[@typescript-eslint/require-await](https://typescript-eslint.io/rules/require-await)
onTeardown: async (): Promise<void> => {
if (spawnedOnFirstBuild) {
spawnedOnFirstBuild.kill();
}
}
Possible Solution
I suggest changing the return type to type Awaitable<T> = T | PromiseLike<T>;
if you don't use .then
s internally