Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ declare class ThreadStream extends EventEmitter {
* @param transferList an optional list of transferable objects to be transferred to the Worker context.
* @returns {boolean} true if the event had listeners, false otherwise.
*/
emit(eventName: 'message', message: any, transferList?: workerThreads.TransferListItem[]): boolean
emit(eventName: 'message', message: any, transferList?: workerThreads.Transferable[]): boolean
}

export = ThreadStream;
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"real-require": "^1.0.0"
},
"devDependencies": {
"@types/node": "^25.0.2",
"@types/node": "^26.1.1",
"@yao-pkg/pkg": "^6.0.0",
"borp": "^1.0.0",
"desm": "^1.3.0",
Expand All @@ -21,16 +21,21 @@
"pino-elasticsearch": "^9.0.0",
"sonic-boom": "^5.0.0",
"ts-node": "^10.8.0",
"tsd": "^0.33.0",
"typescript": "~5.7.3"
},
"scripts": {
"build": "tsc --noEmit",
"lint": "eslint",
"test": "npm run lint && npm run build && npm run transpile && borp --expose-gc --pattern \"test/*.test.{js,mjs}\"",
"test:ci": "npm run lint && npm run transpile && borp --expose-gc --pattern \"test/*.test.{js,mjs}\"",
"test": "npm run lint && npm run build && npm run test:types && npm run transpile && borp --expose-gc --pattern \"test/*.test.{js,mjs}\"",
"test:ci": "npm run lint && npm run test:types && npm run transpile && borp --expose-gc --pattern \"test/*.test.{js,mjs}\"",
"test:types": "tsd",
"test:yarn": "npm run transpile && borp --expose-gc --pattern \"test/*.test.js\"",
"transpile": "sh ./test/ts/transpile.sh"
},
"tsd": {
"directory": "test/types"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mcollina/thread-stream.git"
Expand Down
26 changes: 26 additions & 0 deletions test/types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expectType } from "tsd";
import { type Transferable, MessageChannel } from "worker_threads";
import ThreadStream from "../../index";

const stream = new ThreadStream({ filename: "./worker.js" });

expectType<boolean>(stream.write("hello"));
expectType<void>(stream.end());
expectType<void>(stream.flush());
expectType<void>(stream.flushSync());

// emit overload for posting a message to the worker,
// optionally with a list of transferable objects
const { port1 } = new MessageChannel();
expectType<boolean>(stream.emit("message", { foo: "bar" }));
expectType<boolean>(stream.emit("message", { foo: "bar" }, [port1]));
expectType<boolean>(stream.emit("message", "data", [new ArrayBuffer(8)]));

// the transferList parameter of the 'message' overload must be Transferable[]
// (Parameters<> resolves to the last overload, which is the 'message' one)
expectType<Transferable[] | undefined>(
undefined as unknown as Parameters<ThreadStream["emit"]>[2],
);

// generic EventEmitter emit
expectType<boolean>(stream.emit("drain"));
Loading