fromdeno / deno2node

Compile your Deno project to run on Node.js.
MIT License
115 stars 3 forks source link

feat: support Triple-Slash Lib Directives #36

Closed KnorpelSenf closed 1 year ago

KnorpelSenf commented 1 year ago

Problem

When using web workers, one needs to use

/// <reference no-default-lib="true" />
/// <reference lib="deno.worker" />

to make the code compile on Deno.

However, when this is transformed to Node, there is no way to add a built-in library. Hence, the following error is thrown:

src/worker.ts:2:21 - error TS2726: Cannot find lib definition for 'deno.worker'.

2 /// <reference lib="deno.worker" />
                      ~~~~~~~~~~~

TypeScript 4.9.4
Found 1 errors.

Possible Solutions

  1. Always remove /// <reference lib="deno.worker" /> from source files.
  2. Allow "shimming" built-in libs, so we could create a file deno.worker with the necessary type definitions

Useful Links

KnorpelSenf commented 1 year ago

I'm stupid. Solution 1 can already be used by moving the /// directive to the Deno-specific code. Thanks for @MKRhere for pointing this out. Closing.