Skip to content

Bundle TypeScript declarations#848

Open
imjordanxd wants to merge 1 commit into
archiverjs:masterfrom
imjordanxd:types/bundle-dts
Open

Bundle TypeScript declarations#848
imjordanxd wants to merge 1 commit into
archiverjs:masterfrom
imjordanxd:types/bundle-dts

Conversation

@imjordanxd
Copy link
Copy Markdown

@imjordanxd imjordanxd commented May 30, 2026

Summary

Resolves #838

  • Ships a hand-written index.d.ts matching v8's named-class API (Archiver, ZipArchive, TarArchive, JsonArchive) so consumers no longer need @types/archiver.
  • No new runtime exports. ArchiverError is typed as a structural interface only — index.js and lib/ are byte-identical to master.
  • tsconfig.json enables strict + isolatedDeclarations, a test/types/smoke.test-d.ts exercises every public method and event signature, and CI now runs npm run typecheck before npm test.

Why types in the repo

The existing @types/archiver on DefinitelyTyped describes v7's factory API (archiver(format, options) + registerFormat + export = archiver). v8 reshaped the public API into named class exports, so the DT package is now stale for current users. Bundling types here keeps them in sync with the source going forward and lets the DT package be deprecated.

Relation to #842

#842 (thanks @mjfwalsh) takes the same approach — bundling a DT-adapted index.d.ts. This PR differs in a few ways worth flagging so maintainers can pick the right one.

Bug fixes vs #842

  • ArchiverError is declared as a class with a public constructor in Add typescript type definition file #842. index.js does not re-export ArchiverError, so a consumer doing new ArchiverError(...) or instanceof ArchiverError would crash at runtime. This PR declares it as a structural interface instead — no false claim of a runtime export.
  • setFormat, setModule, use are declared on Archiver in Add typescript type definition file #842. These existed on the v7 factory API and were removed in v8 (lib/core.js has no such methods). Calling any of them today throws TypeError. This PR omits them.
  • TransformOptions typos (writeableObjectMode, objectmode) carry over from DT in Add typescript type definition file #842. This PR re-exports Node's stream.TransformOptions directly, which sidesteps the typos and stays current with Node updates.

Additional coverage

  • tsconfig.json with strict + isolatedDeclarations, plus a type-only smoke test under test/types/ covering every public method and event signature. Add typescript type definition file #842 explicitly punts on tests ("I could add tests for these types but I'd need to add typescript as a dev dep"), so the declarations there can silently drift from source.
  • CI runs npm run typecheck before npm test on Node 18/20.
  • Dual exports conditional map (types + import), not just the bare top-level "types" field.
  • CHANGELOG entry.

If maintainers prefer #842's lighter footprint, the three bugs above are still worth fixing there.

What changed

File Kind
index.d.ts new — declarations
test/types/smoke.test-d.ts new — type-only smoke test
tsconfig.json new — typecheck config (strict, isolatedDeclarations, noEmit)
package.json types + exports map, index.d.ts added to files, typecheck script, typescript + @types/node devDeps
.github/workflows/nodejs.yml added npm run typecheck
CHANGELOG.md Unreleased entry

Test plan

  • npm run typecheck — clean (TypeScript 6.0.3, isolated declarations)
  • npm test — 40/40 passing
  • npx prettier --check — all touched files compliant
  • No changes to index.js or anything in lib/ (verify with git diff master -- index.js lib/)

Follow-up (not in this PR)

Once released, the corresponding types/archiver package on DefinitelyTyped should be marked as not-needed (types are bundled). I'll open that PR after this lands and pre-ping the existing DT owners as a courtesy.

🤖 Generated with Claude Code

Ship a hand-written index.d.ts matching the v8 named-class API
(Archiver, ZipArchive, TarArchive, JsonArchive) so consumers no
longer need @types/archiver. ArchiverError is exposed as a
structural interface only — no new runtime exports.

Adds tsconfig.json with isolatedDeclarations + strict, a
type-only smoke test under test/types/, and a typecheck step
to CI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

@types/archiver needs update to match the exports of new package

1 participant