-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
93d44d4 fixed the types visibility issue reported by me here: #1787 but it didn't quite fix in full how this package can be required at type level
The input code:
// @moduleResolution: node16
// @module: commonjs
import {} from 'solid-js' // types: 1.7.7results in
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("solid-js")' call instead.
To convert this file to an ECMAScript module, create a local package.json file with `{ "type": "module" }`.(1479)
You can also verify this here: https://arethetypeswrong.github.io/?p=solid-js%401.7.7
Your Example Website or App
Steps to Reproduce the Bug or Issue
Configure the tsconfig.json using the mentioned options
Expected behavior
Since at runtime I can require('solid-js'), I should be also able to load this synchronously at type-level
Screenshots or Videos
No response
Platform
N/A
Additional context
TS, rightfully, assumes that this module can't be required in CJS and it might suggest using a dynamic import. Since your package.json#type is set to module and you are using .d.ts files for your type declarations, TS can only assume that those correspond to .js files and that they represent non-requireable modules.
The only true solution to this problem is to ship your types twice. With your current setup, you should be shipping .d.ts and .d.cts declarations.