Skip to content

Typechecking fails with "moduleResolution": "node16" or "nodenext" #6

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

Closed
4 tasks done
jameshfisher opened this issue Jan 26, 2023 · 5 comments
Closed
4 tasks done
Labels
☂️ area/types This affects typings 🤷 no/invalid This cannot be acted upon 👎 phase/no Post cannot or will not be acted on

Comments

@jameshfisher
Copy link
Contributor

Initial checklist

Affected packages and versions

[email protected]

Link to runnable example

https://github.com/jameshfisher/bug-report-remark-node16

Steps to reproduce

Set "moduleResolution" to "node16" or "nodenext" in tsconfig.json.

Run tsc.

Expected behavior

No typechecking errors.

Actual behavior

$ npm run build

> [email protected] build
> tsc

example.ts:10:10 - error TS2367: This comparison appears to be unintentional because the types '"link" | "html" | "strong" | "image" | "text" | "linkReference" | "emphasis" | "delete" | "break" | "footnote" | "inlineCode" | "imageReference" | "footnoteReference"' and '"textDirective"' have no overlap.

10   return p.type === "textDirective";
            ~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/mdast-util-directive/index.d.ts:14:69 - error TS2694: Namespace '"/Users/jim/dev/tmp/test-remark-node16/node_modules/mdast-util-to-markdown/lib/types"' has no exported member 'Context'.

14 export type Context = import('mdast-util-to-markdown/lib/types.js').Context
                                                                       ~~~~~~~

node_modules/mdast-util-directive/index.d.ts:17:41 - error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

17 export type ContainerDirective = import('./complex-types').ContainerDirective
                                           ~~~~~~~~~~~~~~~~~

node_modules/mdast-util-directive/index.d.ts:18:36 - error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

18 export type LeafDirective = import('./complex-types').LeafDirective
                                      ~~~~~~~~~~~~~~~~~

node_modules/mdast-util-directive/index.d.ts:19:36 - error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

19 export type TextDirective = import('./complex-types').TextDirective
                                      ~~~~~~~~~~~~~~~~~


Found 5 errors in 2 files.

Errors  Files
     1  example.ts:10
     4  node_modules/mdast-util-directive/index.d.ts:14

Affected runtime and version

Node 16

Affected package manager and version

npm 8

Affected OS and version

macOS

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 26, 2023
@jameshfisher
Copy link
Contributor Author

The root cause seems to be these lines, which omit the .js extension from the import:

* @typedef {import('./complex-types').ContainerDirective} ContainerDirective
* @typedef {import('./complex-types').LeafDirective} LeafDirective
* @typedef {import('./complex-types').TextDirective} TextDirective

This is an error according to TypeScript policy: microsoft/TypeScript#52412

I suggest these lines should have .js added to them?

jameshfisher added a commit to jameshfisher/mdast-util-directive that referenced this issue Jan 26, 2023
@jameshfisher jameshfisher mentioned this issue Jan 26, 2023
5 tasks
@ChristianMurphy
Copy link
Member

Thanks @jameshfisher!
node16 module resolution support is an ongoing effort across the unified/syntax-tree/remark ecosystems.
Pull requests are welcome!

I appreciate your time opening this.
As this will be going out to 300+ repos, and we don't necessarily want 300+ tracking issues for this. 😅
I'm going to close this issue, but know that:

  • node16 resolution is planned and in progress
  • pull requests helping the effort move forward are welcome and appreciated
  • feel free to follow up with questions or further discussion here or in the syntax-tree discussion board https://github.com/orgs/syntax-tree/discussions

Thanks again! 🙇

@github-actions

This comment has been minimized.

@ChristianMurphy ChristianMurphy added 👯 no/duplicate Déjà vu good first issue 👋 This may be a great place to get started! ☂️ area/types This affects typings labels Jan 26, 2023
@github-actions
Copy link

Hi! Thanks for taking the time to contribute!

Because we treat issues as our backlog, we close duplicates to focus our work and not have to touch the same chunk of code for the same reason multiple times. This is also why we may mark something as duplicate that isn’t an exact duplicate but is closely related.

Thanks,
— bb

@github-actions
Copy link

github-actions bot commented Jan 26, 2023

Hi team! It seems this post is a duplicate, but hasn’t been marked as such. Please post a comment w/ Duplicate of #123(no final .) to do so. See GH docs for more info.

Thanks,
— bb

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Jan 26, 2023
@wooorm wooorm added 🤷 no/invalid This cannot be acted upon and removed 👯 no/duplicate Déjà vu good first issue 👋 This may be a great place to get started! labels Jan 27, 2023
wooorm added a commit that referenced this issue Jan 29, 2023
Closes GH-6.
Closes GH-7.

Reviewed-by: Christian Murphy <[email protected]>
Reviewed-by: Remco Haszing <[email protected]>
Reviewed-by: Titus Wormer <[email protected]>

Co-authored-by: Remco Haszing <[email protected]>
Co-authored-by: Titus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 🤷 no/invalid This cannot be acted upon 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

3 participants