fix: refine type definition for transferList
[poolifier.git] / src / pools / thread / fixed.ts
index 78ef12f87744729733f7434bdbb21a299f286b63..7977cd61abd5263023b855fe9f7f23ba5135de10 100644 (file)
@@ -1,8 +1,9 @@
 import {
+  isMainThread,
   type TransferListItem,
-  type Worker,
-  isMainThread
+  type Worker
 } from 'node:worker_threads'
+
 import type { MessageValue } from '../../utility-types.js'
 import { AbstractPool } from '../abstract-pool.js'
 import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js'
@@ -50,10 +51,13 @@ export class FixedThreadPool<
   protected sendToWorker (
     workerNodeKey: number,
     message: MessageValue<Data>,
-    transferList?: TransferListItem[]
+    transferList?: readonly TransferListItem[]
   ): void {
-    this.workerNodes[workerNodeKey].messageChannel?.port1.postMessage(
-      { ...message, workerId: this.getWorkerInfo(workerNodeKey)?.id },
+    this.workerNodes[workerNodeKey]?.messageChannel?.port1.postMessage(
+      {
+        ...message,
+        workerId: this.getWorkerInfo(workerNodeKey)?.id
+      } satisfies MessageValue<Data>,
       transferList
     )
   }
@@ -68,7 +72,7 @@ export class FixedThreadPool<
         ready: false,
         workerId: this.getWorkerInfo(workerNodeKey)?.id,
         port: port2
-      },
+      } satisfies MessageValue<Data>,
       [port2]
     )
   }