Skip to content

Publish per format type declarations - #1192

Open
manzoorwanijk wants to merge 1 commit into
steveukx:mainfrom
manzoorwanijk:fix/node16-type-declarations
Open

Publish per format type declarations#1192
manzoorwanijk wants to merge 1 commit into
steveukx:mainfrom
manzoorwanijk:fix/node16-type-declarations

Conversation

@manzoorwanijk

Copy link
Copy Markdown

Fixes #1191.

Every entry point resolved to the same CommonJS declarations, checked with arethetypeswrong.

Changes

  • scripts/build-types.js generates a type entry per format from typings/index.d.ts, the CJS one using export = to describe the callable module.exports.
  • Each export condition in package.json declares its own types, so ESM consumers stop resolving CJS declarations.

Before:

simple-git simple-git/promise
node10 ❗️ Incorrect default export ❌ No types
node16 (from CJS) ❗️ Incorrect default export ❌ No types
node16 (from ESM) 🎭 Masquerading as CJS 💀 Resolution failed
bundler 🟢 💀 Resolution failed

After:

simple-git simple-git/promise
node10 🟢 🟢
node16 (from CJS) 🟢 (CJS) 🟢 (CJS)
node16 (from ESM) 🟢 (ESM) 🟢 (CJS)
bundler 🟢 🟢

Testing

yarn build && yarn build:pkg && (cd simple-git && attw --pack .) && yarn build:pkg:reset

Type only tests in test-typescript-esm-consumer cover both node16 conditions and fail with TS2349: This expression is not callable without this change.

Resolves the `This expression is not callable` errors reported under node16
module resolution (steveukx#1191).

- generate `dist/esm/index.d.ts` and `dist/cjs/index.d.ts` from the hand
  written typings, the CJS entry using `export =` to describe the callable
  `module.exports`
- declare `types` per export condition so ESM consumers no longer resolve
  CJS declarations
- add types for the deprecated `simple-git/promise` entry point
- type check the ESM consumer package to cover both node16 conditions
@changeset-bot

changeset-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f5a2e51

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
simple-git Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@manzoorwanijk
manzoorwanijk marked this pull request as ready for review August 28, 2026 11:08
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.

TypeScript types need some improvement.

1 participant