Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type checking ESM with mapped package fails to see types within package #331

Open
MasterKale opened this issue Aug 16, 2023 · 0 comments
Open

Comments

@MasterKale
Copy link

My project uses @hexagon/base64, which cross-publishes to deno.land as b64. I'm experimenting with migrating my Node library to use dnt so I can start cross-publishing as well, and so I updated my import to point to deno.land:

import base64 from "https://deno.land/x/b64@1.1.27/src/base64.js";

Which I then map to the NPM equivalent in my dnt build script:

mappings: {
  'https://deno.land/x/b64@1.1.27/src/base64.js': {
    name: '@hexagon/base64',
    version: '^1.1.25'
  }
},

When I run the build script, the export maps over as expected:

import base64 from "@hexagon/base64";

BUT dnt fails to build when it tries to type check the ESM it just output:

deno task build
Task build deno run -A build_npm.ts 0.0.1
[dnt] Transforming...
[dnt] Running npm install...

added 2 packages, and audited 3 packages in 849ms

found 0 vulnerabilities
[dnt] Building project...
[dnt] Type checking ESM...
src/helpers/iso/isoBase64URL.ts:1:20 - error TS7016: Could not find a declaration file for module '@hexagon/base64'. '/Users/matt/Developer/simplewebauthn/packages/server/npm/node_modules/@hexagon/base64/dist/base64.cjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/hexagon__base64` if it exists or add a new declaration (.d.ts) file containing `declare module '@hexagon/base64';`

1 import base64 from "@hexagon/base64";
                     ~~~~~~~~~~~~~~~~~

error: Uncaught (in promise) Error: Had 1 diagnostics.
          throw new Error(`Had ${diagnostics.length} diagnostics.`);
                ^
    at getProgramAndMaybeTypeCheck (https://deno.land/x/dnt@0.38.0/mod.ts:456:17)
    at build (https://deno.land/x/dnt@0.38.0/mod.ts:345:17)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async file:///Users/matt/Developer/simplewebauthn/packages/server/build_npm.ts:7:1

The @hexagon/base64 package includes its own .d.ts file, though, that has all the type declarations:

Screenshot 2023-08-16 at 9 59 18 AM

It doesn't seem possible to get dnt to see these types. My project currently gets TypeScript to see these types by including "./node_modules/@types" in tsconfig.json's typeRoots (which, I know, doesn't really make sense since @hexagon/base64's types aren't actually in node_modules/@types/ but it works 🤷‍♂️), but typeRoots isn't a valid value for dnt's compilerOptions:

Screenshot 2023-08-16 at 10 03 48 AM

I tried adding /// <reference types="https://deno.land/x/b64@1.1.27/types/base64.d.ts" /> above my deno.land import in the source file, but it just gets stripped out by dnt so that doesn't seem to be an option either.

Any idea how I can get ESM type checking to see this package's types?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant