gajus / turbowatch

Extremely fast file change detector and task orchestrator for Node.js.
Other
938 stars 23 forks source link

Can't define onTeardown/onChange event handlers as non-async #52

Open AlexAegis opened 1 year ago

AlexAegis commented 1 year ago

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 .thens internally