#StackBounty: #node.js #typescript #promise #gulp #typescript-eslint How to handle properly the Gulp's Task function in NodeJS API?

Bounty: 50

Currenly, I know only one working method of runnig the Gulp task without gulpfile and CLI:

import Gulp from "gulp";

const TASK_NAME: string = "EXAMPLE_TASK";

Gulp.task(TASK_NAME, Gulp.parallel([
    // ... imported task fuctions ...

    (error?: Error | null): void => { if (isNeitherUndefinedNorNull(error)) { console.error(error); } }

It is not the subject of question; I just explained what I doing and why my code is such as, but if you know
the better method of executing of Gulp task without gulpfile and CLI, please let me now.

Now about the subject. Until recently, the last part of the code (Gulp.task(TASK_NAME)(/* ... */))
has not been rejected by no-floating-promises rule if typescript-eslint. By after latest update of @types/gulp (or typescript-eslint – now it’s hard to explore which one)
typescript-eslint warn me:

Promises must be handled appropriately or explicitly marked as ignored with the void operator

there. I know it’s not the false alarm. Sometimes my Gulp tasks chain broken with unhandled promise rejection, but it was not obvious where promise was. Now I had the hint, but it’s still unclear.

I explored that:

  1. Gulp.task() returned the Undertaker.TaskFunctionWrapped
  2. TaskFunctionWrapped extends the TaskFunctionBase
  3. TaskFunctionBase is (done: TaskCallback): ReturnType<AsyncTask>;
  4. The AsyncTask is:
export type AsyncTask<R = any> =
  ((done: VoidCallback) => void)
  | ((done: Callback<R>) => void)
  | (() => ChildProcess | EventEmitter | Observable<R> | PromiseLike<R> | Stream);

According documentation, the task function must return the ChildProcess, EventEmitter , Observable, Promise or Stream. But how to handle it? Gult.task()() is not thenable:

enter image description here

Error texting:

TS2339: Property ‘catch’ does not exist on type ‘void | EventEmitter | ChildProcess | Stream | Observable | PromiseLike’.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.