Skip to content
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

TypeScript Playground Shows Inconsistent any for unist-util-visit type #3187

Open
karlhorky opened this issue Jul 23, 2024 · 0 comments
Open

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Jul 23, 2024

First of all, thanks so much for the TypeScript Playground and all other TS tooling, amazing effect on robustness of JS code 🙌

In this issue comment in unist-util-visit, I discovered some inconsistent behavior in the TypeScript Playground:

Actual

In the TypeScript Playground, the type of node in the callback passed to unist-util-visit is any

Playground

/**
 * @import {Root} from 'mdast'
 */

import { visit } from "unist-util-visit";

// TS Playground only: Import `@types/mdast` for JSDoc type imports
import 'mdast';

export function myPlugin() {
  /**
   * @param {Root} tree
   * @returns {undefined}
   */
  return function (tree) {
    visit(tree, 'image', function (node) {
                                // ^? any
    })
  }
}

Expected

...where it is mdast.Image in a local VS Code:

Reproduction repo: https://github.com/karlhorky/repro-unist-util-visit-node-any

/**
 * @import {Root} from 'mdast'
 */

import { visit } from "unist-util-visit";

export function myPlugin() {
  /**
   * @param {Root} tree
   * @returns {undefined}
   */
  return function (tree) {
    visit(tree, 'image', function (node) {
                                // ^? mdast.Image
    })
  }
}

Screenshot 2024-07-22 at 11 13 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant