pinojs / thread-stream

A streaming way to send data to a Node.js Worker Thread
MIT License
229 stars 23 forks source link

Error when compiling with Typescript #150

Closed chrisbenincasa closed 4 months ago

chrisbenincasa commented 5 months ago
@tunarr/server:build: ../node_modules/.pnpm/thread-stream@3.0.0/node_modules/thread-stream/index.d.ts:79:61 - error TS1183: An implementation cannot be declared in ambient contexts.
@tunarr/server:build: 
@tunarr/server:build: 79   emit(eventName: string | symbol, ...args: any[]): boolean {
@tunarr/server:build:                                                                ~
@tunarr/server:build: 
@tunarr/server:build: 
@tunarr/server:build: Found 1 error in ../node_modules/.pnpm/thread-stream@3.0.0/node_modules/thread-stream/index.d.ts:79
@tunarr/server:build: 
@tunarr/server:build:  ELIFECYCLE  Command failed with exit code 2.

This stems from the fact that thread-stream provides implementation in a declaration file, which is not valid Typescript:

https://github.com/pinojs/thread-stream/blob/main/index.d.ts#L79-L82

As a workaround I used pnpm patch with these changes:

https://gist.github.com/chrisbenincasa/498e844fe7033c3230c8abe97c149602

mcollina commented 5 months ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

kylejeske commented 4 months ago

+1 - using this as a dep for any package consuming it will throw an error, unless you turn skipLibCheck to true.

chrisbenincasa commented 4 months ago

I'd be happy to contribute the fix, but hooking up a test for this is a little more involved, since it would require adding a verification build step on the declaration file, which might be a little involved for somebody not familiar with the layout of this repo.