Skip to content

fix: Emit TypeScript type declarations in published package#198

Merged
AntonioVentilii merged 1 commit intomainfrom
fix/emit-typescript-declarations
Apr 17, 2026
Merged

fix: Emit TypeScript type declarations in published package#198
AntonioVentilii merged 1 commit intomainfrom
fix/emit-typescript-declarations

Conversation

@AntonioVentilii
Copy link
Copy Markdown
Collaborator

@AntonioVentilii AntonioVentilii commented Apr 17, 2026

Motivation

The published @dfinity/ic-pub-key npm package is missing .d.ts type declaration files, which breaks standard TypeScript imports. This was reported in #197.

Changes

  • tsconfig.json: Added "declaration": true and "declarationMap": true so that tsc emits .d.ts (and .d.ts.map) files alongside the compiled .js output.
  • tsconfig.json: Added test patterns to exclude (src/**/*.test.ts, src/**/*.tests, src/__tests__) so compiled test files and their declarations are not emitted into dist/.
  • package.json: Fixed the "main" field from "index.js" (non-existent at the root) to "./dist/index.js", and added a "types": "./dist/index.d.ts" field so TypeScript can resolve the package's type declarations.
  • package.json: Added a "files": ["dist"] allowlist so only library artifacts are published.
  • src/index.ts, src/signer/index.ts: Added missing .js extensions to relative import specifiers, consistent with the rest of the codebase. Under "type": "module", Node's ESM resolver requires explicit extensions.

Tests

  • npm run build succeeds and .d.ts files are generated in dist/.
  • All 124 existing tests pass (npm test). Vitest uses its own transform and is unaffected by the tsconfig.json exclude changes.
  • npm pack --dry-run confirms the tarball contains only runtime/library artifacts (42 files, down from 196 on main).

Fixes #197

@AntonioVentilii AntonioVentilii marked this pull request as ready for review April 17, 2026 13:53
@AntonioVentilii AntonioVentilii requested review from a team as code owners April 17, 2026 13:53
Copilot AI review requested due to automatic review settings April 17, 2026 13:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make the published @dfinity/ic-pub-key npm package TypeScript-friendly by ensuring .d.ts declarations are emitted during build and by pointing package entry metadata at the built dist/ artifacts.

Changes:

  • Enable TypeScript declaration and declaration map emission in tsconfig.json.
  • Fix package.json entrypoints by setting main to ./dist/index.js and adding types pointing to ./dist/index.d.ts.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.

File Description
tsconfig.json Enables .d.ts / .d.ts.map emission during tsc builds.
package.json Points runtime entry (main) and TS types entry (types) at dist/ outputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
Comment thread package.json
Comment thread package.json
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
@AntonioVentilii AntonioVentilii force-pushed the fix/emit-typescript-declarations branch from fb69e69 to fedace0 Compare April 17, 2026 14:14
@AntonioVentilii AntonioVentilii added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit e126ccf Apr 17, 2026
12 checks passed
@AntonioVentilii AntonioVentilii deleted the fix/emit-typescript-declarations branch April 17, 2026 15:06
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.

Missing TypeScript type declarations (.d.ts) in published npm package

3 participants