Setting noImplicityAny to true triggers transitive import type declaration errors with moduleResolution NodeNext
See original GitHub issueBug Report
Setting noImplicityAny to true triggers transitive import errors like this, when using "moduleResolution": "nodenext"
:
node_modules/@tiptap/core/dist/packages/core/src/helpers/isTextSelection.d.ts:1:31 - error TS7016: Could not find a declaration file for module 'prosemirror-state'. '/Users/basher/code/prosemirror-nodenext/node_modules/prosemirror-state/dist/index.cjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/prosemirror-state` if it exists or add a new declaration (.d.ts) file containing `declare module 'prosemirror-state';`
1 import { TextSelection } from 'prosemirror-state';
~~~~~~~~~~~~~~~~~~~
In this setup, we’re importing @tiptap/core
, which is importing prosemirror-*
packages. @tiptap/core
is a CommonJS package. prosemirror-*
packages have exports maps and appear to support CommonJS and ESM correctly. I should also note that prosesmirror-*
packages come with their own types (i.e. no @types/*
packages needed)
Setting noImplicitAny to true triggers these errors. Setting it to false makes them disappear (successful compile).
🔎 Search Terms
- nodenext
- esm
- import
🕗 Version & Regression Information
With the TS 4.7 release, we’re trying to migrate to NodeNext as a step to getting to ESM. It wasn’t possible to use NodeNext on prior versions.
⏯ Playground Link
I can’t figure out how to add node_modules to TS Playground, but I’d be happy to provide a playground link, if someone can advise there.
https://github.com/benasher44/prosemirror-nodenext
💻 Code
tsconfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "ESNext",
"esModuleInterop": true,
"lib": [
"DOM",
"DOM.Iterable",
"ES2021"
],
"moduleResolution": "NodeNext",
"outDir": "build",
"allowSyntheticDefaultImports": true,
"strict": true,
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
},
"include": ["src/**/*", "__tests__/**/*"]
}
Add latest @tiptap/core
to package.json (2.0.0-beta.182
in this case)
TS file that imports and consumes a type from @tiptap/core
import { JSONContent } from "@tiptap/core";
export function test(e: JSONContent): void {
console.log(e);
}
🙁 Actual behavior
Errors that show TS can’t find type declaration.
🙂 Expected behavior
Successful compile.
Issue Analytics
- State:
- Created a year ago
- Reactions:12
- Comments:14 (6 by maintainers)
You can also use
--traceResolution
(to see the steps taken during module resolution) and--explainFiles
(to know more information about files like was it treated as CJS or ESM based on package.json, why was file in the program etc)If it’s at all possible to include more fallback behaviors that would make this scenario work, I would be appreciative. It appears I was unsuccessful at convincing this maintainer that this isn’t just a bug in TypeScript https://github.com/ProseMirror/prosemirror/issues/1305#issuecomment-1290284829
Otherwise, we’ll just patch the library locally using yarn’s patch facilities