Skip to content

Commit

Permalink
fix: fix TypeScript type definitions for commonjs
Browse files Browse the repository at this point in the history
This is done by duplicating `index.d.ts` into `index.d.cts`, and
modifying it for CommonJS. The same was done for type tests.

Unfortunately I was unable to find a way to re-use types without
drastically changing the code base.

To test this, a minimum TypeScript version of 4.7 is needed, so it has
been updated. The old types still work with older TypeScript versions.
  • Loading branch information
remcohaszing committed Nov 1, 2022
1 parent 2750eb0 commit 7fd51c3
Show file tree
Hide file tree
Showing 8 changed files with 959 additions and 21 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -1278,6 +1278,12 @@ try {
}
```
Because axios dual publishes with an ESM default export and a CJS `module.exports`, there are some caveats.
The recommended setting is to use `"moduleResolution": "node16"` (this is implied by `"module": "node16"`). Note that this requires TypeScript 4.7 or greater.
If use ESM, your settings should be fine.
If you compile TypeScript to CJS and you can’t use `"moduleResolution": "node 16"`, you have to enable `esModuleInterop`.
If you use TypeScript to type check CJS JavaScript code, your only option is to use `"moduleResolution": "node16"`.
## Online one-click setup
You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.
Expand Down

0 comments on commit 7fd51c3

Please sign in to comment.