Giter VIP home page Giter VIP logo

Comments (16)

kylekampy avatar kylekampy commented on July 3, 2024 2

Alternative to pinning typescript version - you can pin unist-util-visit to 4.0.0 and also avoid the tsc hang.

from unist-util-visit.

ChristianMurphy avatar ChristianMurphy commented on July 3, 2024 1

Thanks for reaching out @cjroebuck and @benatkin! Sorry you ran into a spot of trouble.
This is indeed an issue in TypeScript, @stefanprobst also caught it in unifiedjs/unified#175 and narrowed it down to being a bug which was reported in TypeScript microsoft/TypeScript#46900 (which you've noted as well).
We're all waiting for a fix in TypeScript.
Pinning the TypeScript version to 4.4.3 is the work around for now.

from unist-util-visit.

SilvaQ avatar SilvaQ commented on July 3, 2024 1

I think this could be a temporary solution。
The idea is to solve the problem by switching versions of typescript。
Modify the default typescript mode of vscode as shown in the documentation below:
using-the-workspace-version-of-typescript

steps:

  1. open vscode settings.json
  2. add typescript.tsdk filed
  3. specify the typescript path you want to use

I installed the specified version of the current project:

Modified the vscode configuration file:

       ... other fields here ....
"typescript.tsdk": "./node_modules/typescript/lib"

problem off for me now.

from unist-util-visit.

Saul-Mirone avatar Saul-Mirone commented on July 3, 2024 1

For anyone using pnpm:

https://github.com/Saul-Mirone/milkdown/blob/main/.pnpmfile.cjs

from unist-util-visit.

ChristianMurphy avatar ChristianMurphy commented on July 3, 2024 1

This has been resolved in TypeScript 4.6 https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/#improved-recursion-depth-checks
The fix has also been backported to 4.5

You may already have this change because it was cherry-picked into TypeScript 4.5.3

from unist-util-visit.

cjroebuck avatar cjroebuck commented on July 3, 2024

Please see corresponding issue in next.js vercel/next.js#32193

from unist-util-visit.

cjroebuck avatar cjroebuck commented on July 3, 2024

Looks like it could be a bug in tsc: microsoft/TypeScript#46900

from unist-util-visit.

SilvaQ avatar SilvaQ commented on July 3, 2024

Excuse me, what is the current solution? I've looked at everything and I still can't find a solution.

I don't have a typescript project right now.
Pure JS projects do import {visit} from "unist-util-visit"; the CPU immediately overloads and vscode doesn't work properly

image

from unist-util-visit.

siefkenj avatar siefkenj commented on July 3, 2024

On TS 4.5 this only happens to me if I use the full (node, index, parent) => ... in my visit callback. If I just use (node) => ..., my typescript will actually compile...

Since I am only visiting one type of document, I was able to work around this issue by casing visit to any and the making a wrapper function.

import { Element as XMLElement, Root } from "xast";
import { visit as origVisit } from "unist-util-visit";

const castVisit = origVisit as any;

/**
 * A wrapper around `unist-util-visit` to work around a typescript bug.
 * 
 * See
 * https://github.com/microsoft/TypeScript/issues/46900
 * https://github.com/syntax-tree/unist-util-visit/issues/33
 *
 */
export const xmlVisit = (
    ast: XMLElement | Root,
    test: (...args: any[]) => boolean,
    callback: (
        node: XMLElement,
        index: number | null,
        parent: XMLElement | undefined | null
    ) => any
) => {
    return castVisit(ast, test, callback);
};

from unist-util-visit.

github-actions avatar github-actions commented on July 3, 2024

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

from unist-util-visit.

tefkah avatar tefkah commented on July 3, 2024

Maybe I'm doing something wrong, but this problem still persists for me on Typescript 4.6.3

from unist-util-visit.

wooorm avatar wooorm commented on July 3, 2024

it should work. Latest TS + latest this package. We’re using it in many places.

from unist-util-visit.

tefkah avatar tefkah commented on July 3, 2024

You're right, I apologise! It does seem to take tsc some more time to compile everything and provide type hinting, but once it has all the info it works. I was being impatient 😅

from unist-util-visit.

jemgold avatar jemgold commented on July 3, 2024

has anyone figured out a good solve for this problem? Still having the same issue in 4.9.4

import type { Root } from 'mdast'

export const autolinkContract: U.Plugin<[], Root> = () => {
  return tree => {
    // tree is correctly cast to mdast.Root
    visit(tree, 'text', (node, index, parent) => {
      // node, index & parent eventually get narrowed correctly
      // but it's suuuuuper slow in VSCode
    })
  }
}

from unist-util-visit.

ChristianMurphy avatar ChristianMurphy commented on July 3, 2024

@jemgold yes, use typescript 4.9.3 or newer both for TSC and in VSCode as well.
You are likely still seeing the issue because VSCode by default ships its own version of TypeScript, which is likely not as up-to-date as the one configured in your package.json file.
You can find out more on how to configure the TypeScript version VSCode uses in their docs:
https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-newer-typescript-versions


If you have a full replication of the issue in a newer version of TypeScript, please report the regression to the TypeScript team so they can fix it.

from unist-util-visit.

ChristianMurphy avatar ChristianMurphy commented on July 3, 2024

Locking this issue as:

  1. not an issue in unist-util-visit, it was an upstream issue in TypeScript itself
  2. it was solved a year ago by TypeScript

Feel free to open a discussion for any questions.
Or open a new issue if you believe a new issue has happened, which does not originate in TypeScript itself.

from unist-util-visit.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.