Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ivancuric opened this issue Oct 17, 2023 · 3 comments

Comments

@ivancuric
Copy link

ivancuric commented Oct 17, 2023

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/is-plain-object@5.0.0

image

@ericmorand
Copy link

ericmorand commented Oct 17, 2023

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?

@ivancuric
Copy link
Author

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

@ericmorand
Copy link

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.

@ivancuric ivancuric changed the title Invalid types for modern module resolution formats Missing types when using moduleResolution set to next, node16 or bundler Oct 17, 2023
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

No branches or pull requests

2 participants