Skip to content

fix(types): describe the CommonJS export with export = - #56

Merged
Kikobeats merged 1 commit into
masterfrom
Kikobeats/fix-types-export
Oct 29, 2026
Merged

Kikobeats merged 1 commit into
masterfrom
Kikobeats/fix-types-export

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Bug

index.js is CommonJS (module.exports = KeyvS3, a class), but index.d.ts declared export default class KeyvS3 and export { KeyvS3 as KeyvS3Class }. TypeScript therefore believed in .default and .KeyvS3Class properties that do not exist at runtime.

  • ESM consumer (module: nodenext): import KeyvS3 from 'keyv-s3'; new KeyvS3({...}) fails with TS2351: This expression is not constructable.
  • CJS consumer without esModuleInterop: import KeyvS3 from 'keyv-s3' compiles, and KeyvS3 is undefined at runtime.

Separately, index.js and index.d.ts require @aws-sdk/client-s3, but it was only a devDependency, so a plain npm install keyv-s3 could not load the package or resolve its types (TS2307).

Fix

  • export = KeyvS3, with KeyvS3Options, PutObjectOptions and DeleteObjectOptions moved into a merged declare namespace KeyvS3. import type { ... } from 'keyv-s3' keeps working.
  • KeyvS3Class is now a type-only alias of the instance type: import type { KeyvS3Class } keeps compiling, while value use (which was undefined at runtime) becomes a compile error.
  • @aws-sdk/client-s3 is declared as a peerDependency (^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):

FAIL cjs: import = require compiles (no skipLibCheck)
     node_modules/keyv-s3/index.d.ts(1,31): error TS2307: Cannot find module '@aws-sdk/client-s3' or its corresponding type declarations.
FAIL cjs: import = require runtime is unloadable
     Error: Cannot find module '@aws-sdk/client-s3'
FAIL cjs+esModuleInterop: default import compiles
FAIL cjs+esModuleInterop: default import runtime is unloadable
ok   cjs without esModuleInterop: default import is a type error (TS1259) (rejected as expected)
FAIL esm nodenext: default import is the module, not { default }
     esm/index.mts(3,14): error TS2322: Type 'false' is not assignable to type 'true'.
FAIL keyv-s3

After (this branch):

ok   cjs: import = require compiles (no skipLibCheck)
ok   cjs: import = require runtime is function
ok   cjs+esModuleInterop: default import compiles
ok   cjs+esModuleInterop: default import runtime is function
ok   cjs without esModuleInterop: default import is a type error (TS1259) (rejected as expected)
ok   esm nodenext: default import is the module, not { default }
ok   esm nodenext: consumer usage (keyv-s3.mts)
PASS keyv-s3

Regression test: test/types.mts is checked by npm run test:types (tsc --noEmit, nodenext), which runs first in npm test. With the master index.d.ts:

test/types.mts(14,32): error TS2351: This expression is not constructable.
test/types.mts(20,1): error TS2578: Unused '@ts-expect-error' directive.

CI: the test job needs S3/B2 credentials for the ava suite and times out on them (known, unrelated to this change). test:types and lint run before ava in that job.

Who has to change their import

  • import KeyvS3 from 'keyv-s3' with esModuleInterop or under nodenext: no change, and new KeyvS3() now compiles under nodenext.
  • require('keyv-s3') / import KeyvS3 = require(...): no change.
  • CJS without esModuleInterop: import x from now fails with TS1259 instead of being undefined at runtime.
  • typeof KeyvS3Class (value-side use of the alias) no longer compiles; use typeof KeyvS3. KeyvS3Class as a type is unchanged.

🤖 Generated with Claude Code


Note

Low Risk
Types and package metadata only; consumers on CJS without esModuleInterop or value-side KeyvS3Class may need import adjustments.

Overview
Aligns TypeScript with the runtime CommonJS shape (module.exports = KeyvS3) by replacing export default / value KeyvS3Class with export = KeyvS3 and merging option types under a declare namespace KeyvS3. Default and require-style imports should match runtime under nodenext and esModuleInterop; KeyvS3Class stays as a type alias only.

Declares @aws-sdk/client-s3 as a peer dependency so installs resolve the module/types the declarations already reference. Adds npm run test:types (tsc --noEmit on test/types.mts) ahead of the existing ava suite, plus TypeScript dev tooling.

No changes to index.js runtime behavior.

Reviewed by Cursor Bugbot for commit 2dc185b. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 376eb64e-5358-4a02-841d-fbe30c495194
Commits

Reviewing files that changed from the base of the PR and between 1bd2fbf and 2dc185b.

Files selected for processing: 3
  • index.d.ts
  • package.json
  • test/types.mts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Kikobeats
Kikobeats merged commit c6a94af into master Oct 29, 2026
4 checks passed
@Kikobeats
Kikobeats deleted the Kikobeats/fix-types-export branch October 29, 2026 08:14
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.

1 participant