Skip to content

Publish per format type declarations - #1192

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

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
@steveukx

Copy link
Copy Markdown
Owner

Hello, thank you for the pull request.

This change attempts to add additional support for the /promise entrypoint which has been deprecated since v2, and node engine versions that are fully EOL.

As this doesn't align with the future-state of the library I will close the PR. Please create a new Issue if you are having a problem that creates the need for such a change.

@steveukx steveukx closed this Sep 14, 2026
@manzoorwanijk

Copy link
Copy Markdown
Author

What a pity!

This change attempts to add additional support for the /promise entrypoint which has been deprecated since v2, and node engine versions that are fully EOL.

But it's the problem with the root entrypoint as well. That fix for /promise was merely to make it all green. 🤷

Please create a new Issue if you are having a problem that creates the need for such a change.

I guess you didn't see the linked issue - #1191

@steveukx

Copy link
Copy Markdown
Owner

The linked report shows that this is needed for node engines 16 and below - these are now fully end of life:

https://nodejs.org/en/about/previous-releases#looking-for-the-latest-release-of-a-version-branch

If this is an issue on node 22 or newer, please include an example of how the library is being imported with the error generated to give clarity to the reason for the change.

@manzoorwanijk

Copy link
Copy Markdown
Author

The linked report shows that this is needed for node engines 16 and below - these are now fully end of life

It’s not the Node version, it’s the resolution algorithm used in Node 16 or greater.

@manzoorwanijk

manzoorwanijk commented Sep 14, 2026

Copy link
Copy Markdown
Author

Sorry, I should have been clearer. "node16" here is TypeScript's moduleResolution mode, which is also what nodenext uses. It isn't the Node.js version. This reproduces on Node 24 with the latest simple-git (3.36.0) and TypeScript:

tsconfig.json

{ "compilerOptions": { "module": "nodenext", "strict": true, "noEmit": true } }

index.ts (package has "type": "module")

import simpleGit from 'simple-git';

const git = simpleGit();
index.ts(3,13): error TS2349: This expression is not callable.
  Type 'typeof import(".../node_modules/simple-git/dist/typings/index")' has no call signatures.

The same error happens for import simpleGit = require('simple-git') in a .cts file. Both work at runtime, but the types don't describe them. That's because exports points import and require at one CJS-style declaration file. You can see it for the published package here: https://arethetypeswrong.github.io/?p=simple-git

I'm happy to drop the /promise part if that makes the change easier to accept.

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.

2 participants