Skip to content

Setting noImplicityAny to true triggers transitive import type declaration errors with moduleResolution NodeNext #50223

Closed
@benasher44

Description

@benasher44

Bug 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.

Metadata

Metadata

Assignees

Labels

ExternalRelates to another program, environment, or user action which we cannot control.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions