refactor: cleanup type casting
[poolifier.git] / src / worker / abstract-worker.ts
index 9b9ded5e9d1cc1267846fb9e0279d88de405262f..ec77ccab8d68c7990339b9331cf6fd4903a7d1fe 100644 (file)
@@ -355,9 +355,10 @@ export abstract class AbstractWorker<
     switch (taskFunctionOperation) {
       case 'add':
         response = this.addTaskFunction(taskFunctionProperties.name, {
-          // eslint-disable-next-line no-new-func
+          // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
           taskFunction: new Function(
-            `return ${taskFunction}`
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            `return ${taskFunction!}`
           )() as TaskFunction<Data, Response>,
           ...(taskFunctionProperties.priority != null && {
             priority: taskFunctionProperties.priority,
@@ -398,7 +399,7 @@ export abstract class AbstractWorker<
   protected handleKillMessage (message: MessageValue<Data>): void {
     this.stopCheckActive()
     if (isAsyncFunction(this.opts.killHandler)) {
-      ;(this.opts.killHandler() as Promise<void>)
+      ;(this.opts.killHandler as () => Promise<void>)()
         .then(() => {
           this.sendToMainWorker({ kill: 'success' })
           return undefined
@@ -408,7 +409,7 @@ export abstract class AbstractWorker<
         })
     } else {
       try {
-        this.opts.killHandler?.()
+        ;(this.opts.killHandler as (() => void) | undefined)?.()
         this.sendToMainWorker({ kill: 'success' })
       } catch {
         this.sendToMainWorker({ kill: 'failure' })
@@ -426,7 +427,7 @@ export abstract class AbstractWorker<
       throw new Error('Message worker id is not set')
     } else if (message.workerId !== this.id) {
       throw new Error(
-        `Message worker id ${message.workerId} does not match the worker id ${this.id}`
+        `Message worker id ${message.workerId.toString()} does not match the worker id ${this.id.toString()}`
       )
     }
   }
@@ -514,7 +515,8 @@ export abstract class AbstractWorker<
         workerError: {
           // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
           name: name!,
-          message: `Task function '${name}' not found`,
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          message: `Task function '${name!}' not found`,
           data,
         },
         taskId,