Skip to content

test type infer is wrong when test is an array #17

@charliez0

Description

@charliez0

Initial checklist

Affected package

unist-util-visit-parents@6..0.0

Steps to reproduce

import { SKIP, visitParents } from 'unist-util-visit-parents'; import type { Root } from 'mdast'; export default function remarkDirectiveRehype() { return function (tree: Root) { visitParents(tree, 'containerDirective', (node) => { // now node.type infers to 'containerDirective', correct! }); }; }
import { SKIP, visitParents } from 'unist-util-visit-parents'; import type { Root } from 'mdast'; export default function remarkDirectiveRehype() { return function (tree: Root) { visitParents(tree, ['containerDirective', 'leafDirective', 'textDirective'], (node) => { // now node.type infers to every possible nodes, incorrect! }); }; }

Actual behavior

(property) type: "containerDirective" | "leafDirective" | "textDirective" | "root" | "blockquote" | "break" | "code" | "definition" | "delete" | "emphasis" | "footnoteDefinition" | "footnoteReference" | "heading" | "html" | "image" | "imageReference" | "inlineCode" | "link" | "linkReference" | "list" | "listItem" | "paragraph" | "strong" | "table" | "tableCell" | "tableRow" | "text" | "thematicBreak" | "yaml" | "inlineMath" | "math"

Expected behavior

(property) type: "containerDirective" | "leafDirective" | "textDirective"

Runtime

node@22.16.0

Package manager

pnpm@10.17.1

Operating system

Windows 11

Build and bundle tools

Astro

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