Bundle TypeScript declarations#848
Open
imjordanxd wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #838
index.d.tsmatching v8's named-class API (Archiver,ZipArchive,TarArchive,JsonArchive) so consumers no longer need@types/archiver.ArchiverErroris typed as a structuralinterfaceonly —index.jsandlib/are byte-identical to master.tsconfig.jsonenablesstrict+isolatedDeclarations, atest/types/smoke.test-d.tsexercises every public method and event signature, and CI now runsnpm run typecheckbeforenpm test.Why types in the repo
The existing
@types/archiveron 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
ArchiverErroris declared as a class with a public constructor in Add typescript type definition file #842.index.jsdoes not re-exportArchiverError, so a consumer doingnew ArchiverError(...)orinstanceof ArchiverErrorwould crash at runtime. This PR declares it as a structuralinterfaceinstead — no false claim of a runtime export.setFormat,setModule,useare declared onArchiverin Add typescript type definition file #842. These existed on the v7 factory API and were removed in v8 (lib/core.jshas no such methods). Calling any of them today throwsTypeError. This PR omits them.TransformOptionstypos (writeableObjectMode,objectmode) carry over from DT in Add typescript type definition file #842. This PR re-exports Node'sstream.TransformOptionsdirectly, which sidesteps the typos and stays current with Node updates.Additional coverage
tsconfig.jsonwithstrict+isolatedDeclarations, plus a type-only smoke test undertest/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.npm run typecheckbeforenpm teston Node 18/20.exportsconditional map (types+import), not just the bare top-level"types"field.If maintainers prefer #842's lighter footprint, the three bugs above are still worth fixing there.
What changed
index.d.tstest/types/smoke.test-d.tstsconfig.jsonstrict,isolatedDeclarations,noEmit)package.jsontypes+exportsmap,index.d.tsadded tofiles,typecheckscript,typescript+@types/nodedevDeps.github/workflows/nodejs.ymlnpm run typecheckCHANGELOG.mdTest plan
npm run typecheck— clean (TypeScript 6.0.3, isolated declarations)npm test— 40/40 passingnpx prettier --check— all touched files compliantindex.jsor anything inlib/(verify withgit diff master -- index.js lib/)Follow-up (not in this PR)
Once released, the corresponding
types/archiverpackage 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