alexreardon / tiny-invariant

A tiny invariant function

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v1.3.0: TypeScript issue when importing `tiny-invariant` from an CJS codebase and `"moduleResolution"` is set to `"node16"`

pkerschbaum opened this issue Β· comments

πŸ•— Version & Regression Information

1.3.0

⏯ Playground Link

https://stackblitz.com/edit/node-cwmfq6

  1. Run npm install.
  2. Run tsc compilation via npm run build. The error occurs.

Problem

If tiny-invariant is used from an TypeScript CJS package with moduleResolution node16, this means:

  • "type" in package.json is not set or set to commonjs
  • and "moduleResolution": "node16" set in tsconfig.json

...then TypeScript cannot find the types:

❯ npm run build
$ tsc
src/test.ts:1:23 - error TS7016: Could not find a declaration file for module 'tiny-invariant'. '/home/projects/node-cwmfq6/node_modules/tiny-invariant/dist/tiny-invariant.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/tiny-invariant` if it exists or add a new declaration (.d.ts) file containing `declare module 'tiny-invariant';`

1 import invariant from 'tiny-invariant';
                        ~~~~~~~~~~~~~~~~


Found 1 error in src/test.ts:1

Reason

See #150.

@pkerschbaum do you think I should deprecate 1.3.0 on npm?

Yes let's do that...

Fixed by #150