Skip to content

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

Closed as not planned
@rickmzp

Description

@rickmzp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    👎 phase/noPost cannot or will not be acted on🙋 no/questionThis does not need any changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions