Skip to content

Allow importing with exports-aware Typescript #4

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

Merged
merged 1 commit into from
May 8, 2025

Conversation

charlag
Copy link
Contributor

@charlag charlag commented Apr 24, 2025

Trying to import the library could run into the following issue:

error TS7016: Could not find a declaration file for module '@signalapp/sqlcipher'. '.../node_modules/@signalapp/sqlcipher/dist/index.mjs' implicitly has an 'any' type.
There are types at '.../node_modules/@signalapp/sqlcipher/dist/lib/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@signalapp/sqlcipher' library may need to update its package.json or typings.

The issue comes from mismatch where index.mjs does not automatically
map to index.d.ts (it would have to be index.d.mts).

The solution is to add types to export. The other "type" key could
be removed but is left in for now for compatibility with old tsc
versions.

The issue was discussed here:
microsoft/TypeScript#52363

And here is an example of the similar solution in another library:
onsetsoftware/automerge-patcher#1

Copy link
Contributor

@indutny-signal indutny-signal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@indutny-signal
Copy link
Contributor

@charlag thank you for the Pull Request! Could you take look at the Contributor License Agreement and fill the form if it is alright with you?

@charlag
Copy link
Contributor Author

charlag commented Apr 28, 2025

hi! yes, I'm waiting for the approval from my employer

@charlag
Copy link
Contributor Author

charlag commented Apr 29, 2025

CLA signed.
Note that there are warnings from esbuild about the new export, I'm not sure if they can be suppressed

Trying to import the library could run into the following issue:

 error TS7016: Could not find a declaration file for module '@signalapp/sqlcipher'. '.../node_modules/@signalapp/sqlcipher/dist/index.mjs' implicitly has an 'any' type.
  There are types at '.../node_modules/@signalapp/sqlcipher/dist/lib/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@signalapp/sqlcipher' library may need to update its package.json or typings.

  The issue comes from mismatch where index.mjs does not automatically
  map to index.d.ts (it would have to be index.d.mts).

  The solution is to add types to export. The other "type" key could
  be removed but is left in for now for compatibility with old tsc
  versions.
@charlag charlag force-pushed the package-json-export-types branch from 28a0bc5 to c0f9cfa Compare May 2, 2025 12:25
@charlag
Copy link
Contributor Author

charlag commented May 2, 2025

I rebased it and put the types condition first so that esbuild does not complain

@charlag charlag force-pushed the package-json-export-types branch 3 times, most recently from bdcdea2 to c0f9cfa Compare May 2, 2025 14:34
@indutny-signal indutny-signal merged commit 2cf0ed0 into signalapp:main May 8, 2025
7 checks passed
@indutny-signal
Copy link
Contributor

Thank you! This will be released in 2.0.2 shortly ❤️

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

Successfully merging this pull request may close these issues.

3 participants