Abort signals and node compatibility
Deno and Node's
AbortSignal
types are not compatible. I have verified that I can use a deno AbortSignal with the node:events
APIs (at least EventEmitter.once()
, but I have to cast them to Node's own type if I want to get rid of errors:
Without the cast, I get the error below.
Is there a better/cleaner way?
Thanks.3 Replies
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you've provided, it seems like you are trying to integrate Deno's
AbortSignal
with Node's EventEmitter
from the node:events
module.
From what you've described, it appears that you are encountering type compatibility issues between Deno and Node's AbortSignal
types. Your current workaround involves casting the Deno AbortSignal
to the Node type to avoid type errors.
While I cannot provide a solution based on the Deno documentation, I can confirm that your approach of casting types is a common workaround when dealing with type incompatibilities in TypeScript. However, please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of this advice.
If you are looking for a cleaner way to handle this, you might want to consider creating a utility function or a wrapper that handles the casting for you, so you don't have to manually cast each time you use the AbortSignal
with Node's EventEmitter
. This could encapsulate the type casting logic in one place and make your codebase cleaner.
Remember to keep an eye on the Deno and Node.js release notes for any updates that might address this compatibility issue in the future.Can you file an issue for that on the deno repository? This is something that should work imo
@marvinh. done: https://github.com/denoland/deno/issues/21860
GitHub
Deno's AbortSignal type isn't compatible with Node APIs · Issue #21...
Version: Deno 1.39.1 I have verified that I can use a deno AbortSignal with the node:events APIs (at least with EventEmitter.once(), but I have to cast them to Node's own type if I want to get ...