Repository navigation
fix(types): describe the CommonJS export with export = - #56
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Bug
index.jsis CommonJS (module.exports = KeyvS3, a class), butindex.d.tsdeclaredexport default class KeyvS3andexport { KeyvS3 as KeyvS3Class }. TypeScript therefore believed in.defaultand.KeyvS3Classproperties that do not exist at runtime.module: nodenext):import KeyvS3 from 'keyv-s3'; new KeyvS3({...})fails withTS2351: This expression is not constructable.esModuleInterop:import KeyvS3 from 'keyv-s3'compiles, andKeyvS3isundefinedat runtime.Separately,
index.jsandindex.d.tsrequire@aws-sdk/client-s3, but it was only a devDependency, so a plainnpm install keyv-s3could not load the package or resolve its types (TS2307).Fix
export = KeyvS3, withKeyvS3Options,PutObjectOptionsandDeleteObjectOptionsmoved into a mergeddeclare namespace KeyvS3.import type { ... } from 'keyv-s3'keeps working.KeyvS3Classis now a type-only alias of the instance type:import type { KeyvS3Class }keeps compiling, while value use (which wasundefinedat runtime) becomes a compile error.@aws-sdk/client-s3is declared as apeerDependency(^3.0.0). The README already tells users to install it; npm 7+ and pnpm now install it automatically. The devDependency pin stays.No runtime code changes.
Proof
Packed tarball compiled as a consumer in every module mode, without
skipLibCheck:Before (master):
After (this branch):
Regression test:
test/types.mtsis checked bynpm run test:types(tsc --noEmit, nodenext), which runs first innpm test. With the masterindex.d.ts:CI: the
testjob needs S3/B2 credentials for the ava suite and times out on them (known, unrelated to this change).test:typesand lint run before ava in that job.Who has to change their import
import KeyvS3 from 'keyv-s3'withesModuleInteropor undernodenext: no change, andnew KeyvS3()now compiles undernodenext.require('keyv-s3')/import KeyvS3 = require(...): no change.esModuleInterop:import x fromnow fails with TS1259 instead of beingundefinedat runtime.typeof KeyvS3Class(value-side use of the alias) no longer compiles; usetypeof KeyvS3.KeyvS3Classas a type is unchanged.🤖 Generated with Claude Code
Note
Low Risk
Types and package metadata only; consumers on CJS without
esModuleInteropor value-sideKeyvS3Classmay need import adjustments.Overview
Aligns TypeScript with the runtime CommonJS shape (
module.exports = KeyvS3) by replacingexport default/ valueKeyvS3Classwithexport = KeyvS3and merging option types under adeclare namespace KeyvS3. Default andrequire-style imports should match runtime undernodenextandesModuleInterop;KeyvS3Classstays as a type alias only.Declares
@aws-sdk/client-s3as a peer dependency so installs resolve the module/types the declarations already reference. Addsnpm run test:types(tsc --noEmitontest/types.mts) ahead of the existing ava suite, plus TypeScript dev tooling.No changes to
index.jsruntime behavior.Reviewed by Cursor Bugbot for commit 2dc185b. Bugbot is set up for automated code reviews on this repo. Configure here.