Hi there! My team is attempting to import this package into a CommonJS file and we're running into TypeScript compilation errors. After doing a bit of investigation, we noticed that tinybench uses the same types for both the CommonJS and ESM builds, which is generally discouraged.
In this pull request, I made the following changes:
[x] Upgraded tsup to the latest version, which will produce separate type declaration files for the CJS and ESM builds
[x] Consolidated a few configuration options in tsup.config.ts and tsconfig.json
[x] Updated the exports object in the package.json to correctly point to the new type declaration files. Since tsup colocates the .js. and .d.ts files (e.g., index.js has a corresponding index.d.ts and index.cjs has a corresponding index.d.cts), there's no need to explicitly specify the paths to the type declaration files.
[x] Removed the default export from src/index.ts since there's already a named export. Default exports are discouraged for libraries that ship both CommonJS and ES modules and was likely part of the type issues in this repository — see here for a great explainer on why.
Hi there! My team is attempting to import this package into a CommonJS file and we're running into TypeScript compilation errors. After doing a bit of investigation, we noticed that
tinybench
uses the same types for both the CommonJS and ESM builds, which is generally discouraged.You can check out "Are The Types Wrong?" for a handy analysis of this: https://arethetypeswrong.github.io/?p=tinybench@2.8.0
I also created a minimal reproduction of the error in this repository.
In this pull request, I made the following changes:
tsup
to the latest version, which will produce separate type declaration files for the CJS and ESM buildstsup.config.ts
andtsconfig.json
exports
object in thepackage.json
to correctly point to the new type declaration files. Sincetsup
colocates the.js
. and.d.ts
files (e.g.,index.js
has a correspondingindex.d.ts
andindex.cjs
has a correspondingindex.d.cts
), there's no need to explicitly specify the paths to the type declaration files.default
export fromsrc/index.ts
since there's already a named export. Default exports are discouraged for libraries that ship both CommonJS and ES modules and was likely part of the type issues in this repository — see here for a great explainer on why.I confirmed that these changes fixed the issues by testing this against the "Are The Types Wrong?" CLI.
Before:
After:
Thanks for your work on this tool and thanks in advance for the review!