is-plain-object icon indicating copy to clipboard operation
is-plain-object copied to clipboard

Missing types when using `moduleResolution` set to `next`, `node16` or `bundler`

Open ivancuric opened this issue 10 months ago • 3 comments

If using TS with moduleResolution set to node16, nodenext or bundler, you get the following message:

Could not find a declaration file for module 'is-plain-object'. 'stackblitz:/node_modules/is-plain-object/dist/is-plain-object.mjs' implicitly has an 'any' type. There are types at 'stackblitz:/node_modules/is-plain-object/is-plain-object.d.ts', but this result could not be resolved when respecting package.json "exports". The 'is-plain-object' library may need to update its package.json or typings.(7016)

Repro on Stackblitz: https://stackblitz.com/edit/vitejs-vite-caqzew?file=package.json,src%2Fmain.ts&terminal=dev

More info on why this happens can be found on arethetypeswrong/arethetypeswrong.github.io

Link to the type analysis and the output:

https://arethetypeswrong.github.io/?p=is-plain-object%405.0.0

Problems ❌ No types

Import resolved to JavaScript files, but no type declarations were found.

  "is-plain-object" "is-plain-object/package.json"
node10 ✅ (JSON)
node16 (from CJS) ❌ No types ✅ (JSON)
node16 (from ESM) ❌ No types ✅ (JSON)
bundler ❌ No types ✅ (JSON)

Another package linter output: https://publint.dev/[email protected]

image

ivancuric avatar Oct 17 '23 14:10 ivancuric

Well, I'm not sure I understand what node16 (from CJS), node16 (from ESM) or bundler mean, but the following code compiles and runs perfectly:

// index.ts
import {isPlainObject} from "is-plain-object";

console.log(isPlainObject(5));
tsc index.ts --strict
node --version
v16.20.2
node index.js
false

This code fails though:

// index.ts
import {isPlainObject} from "is-plain-object";

console.log(isPlainObject(5, 2)); // 
tsc index.ts --strict
index.ts:3:30 - error TS2554: Expected 1 arguments, but got 2.

3 console.log(isPlainObject(5, 2));
                               ~


Found 1 error in index.ts:3

So, clearly, it proves that the types are perfectly resolved by the TypeScript compiler - and by my IDE's IntelliSense too.

Did you actually encounter an issue yourself? If so, can you please describe it?

ericmorand avatar Oct 17 '23 15:10 ericmorand

If using TS with moduleResolution set to node16, nodenext or bundler, you get the following message:

Could not find a declaration file for module 'is-plain-object'. 'stackblitz:/node_modules/is-plain-object/dist/is-plain-object.mjs' implicitly has an 'any' type. There are types at 'stackblitz:/node_modules/is-plain-object/is-plain-object.d.ts', but this result could not be resolved when respecting package.json "exports". The 'is-plain-object' library may need to update its package.json or typings.(7016)

Here's a repro: https://stackblitz.com/edit/vitejs-vite-caqzew?file=package.json,src%2Fmain.ts&terminal=dev

You can read more info about why this happens at https://github.com/arethetypeswrong/arethetypeswrong.github.io

ivancuric avatar Oct 17 '23 19:10 ivancuric

Thanks, I know why it happens. I think you should update the issue description to explain the issue as you explained it on your last comment, though.

ericmorand avatar Oct 17 '23 19:10 ericmorand