Skip to content

Typescript compile issue: Type 'string' is not assignable to type '"root"'. #69

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
rickmzp opened this issue Jun 7, 2025 · 3 comments
Closed
4 tasks done
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@rickmzp
Copy link

rickmzp commented Jun 7, 2025

Initial checklist

Affected package

mdast-util-to-markdown

Steps to reproduce

With version 2.1.2:

import { toMarkdown } from 'mdast-util-to-markdown';

const tree = {
  type: 'root',
  children: [
    {type: 'paragraph', children: [{type: 'text', value: 'a'}]},
    {type: 'thematicBreak'},
    {type: 'paragraph', children: [{type: 'text', value: 'b'}]}
  ]
};

const markdown = toMarkdown(tree);
console.log(markdown);

Run with tsc case.ts

Actual behavior

case.ts:12:29 - error TS2345: Argument of type '{ type: string; children: ({ type: string; children: { type: string; value: string; }[]; } | { type: string; children?: undefined; })[]; }' is not assignable to parameter of type 'Nodes'.
  Type '{ type: string; children: ({ type: string; children: { type: string; value: string; }[]; } | { type: string; children?: undefined; })[]; }' is not assignable to type 'Root'.
    Types of property 'type' are incompatible.
      Type 'string' is not assignable to type '"root"'.

12 const markdown = toMarkdown(tree);
                               ~~~~


Found 1 error in case.ts:12

Expected behavior

Output of:

a

***

b

Runtime

[email protected], Typescript 5.8.3

Package manager

[email protected]

Operating system

macOS 15.4.1

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 Jun 7, 2025
@rickmzp rickmzp changed the title Typescript compile issue Typescript compile issue: Type 'string' is not assignable to type '"root"'. Jun 7, 2025
@remcohaszing
Copy link
Member

Add a type annotation.

+ import { Root } from 'mdast'
  import { toMarkdown } from 'mdast-util-to-markdown';

- const tree = {
+ const tree: Root = {
    type: 'root',
    children: [
      {type: 'paragraph', children: [{type: 'text', value: 'a'}]},
      {type: 'thematicBreak'},
      {type: 'paragraph', children: [{type: 'text', value: 'b'}]}
    ]
  };

  const markdown = toMarkdown(tree);
console.log(markdown);

@remcohaszing remcohaszing closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2025

This comment has been minimized.

@remcohaszing remcohaszing added 🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Jun 7, 2025
Copy link

github-actions bot commented Jun 7, 2025

Hi! Thanks for reaching out! Because we treat issues as our backlog, we close issues that are questions since they don’t represent a task to be completed.

See our support docs for how and where to ask questions.

Thanks,
— bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants