Comments (16)
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.
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.
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:
- open vscode settings.json
- add typescript.tsdk filed
- specify the typescript path you want to use
I installed the specified version of the current project:
yarn add [email protected]
Modified the vscode configuration file:
... other fields here ....
"typescript.tsdk": "./node_modules/typescript/lib"
problem off for me now.
from unist-util-visit.
For anyone using pnpm:
https://github.com/Saul-Mirone/milkdown/blob/main/.pnpmfile.cjs
from unist-util-visit.
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.
Please see corresponding issue in next.js vercel/next.js#32193
from unist-util-visit.
Looks like it could be a bug in tsc: microsoft/TypeScript#46900
from unist-util-visit.
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
from unist-util-visit.
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.
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.
Maybe I'm doing something wrong, but this problem still persists for me on Typescript 4.6.3
from unist-util-visit.
it should work. Latest TS + latest this package. We’re using it in many places.
from unist-util-visit.
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.
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.
@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.
Locking this issue as:
- not an issue in
unist-util-visit
, it was an upstream issue in TypeScript itself - 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)
- Is the API synchronous? HOT 2
- Can transformations be immutable? HOT 6
- Special character parsing HOT 2
- Add types HOT 7
- [Types]: type of parent should be Parent HOT 3
- Standalone documentation HOT 3
- Error [ERR_REQUIRE_ESM]: Must use import to load ES Module HOT 14
- NPM readme example still uses require() HOT 3
- Type doesn't work when using array of tests HOT 7
- Cannot find module 'unist-util-is/lib/index.js' or its corresponding type declarations HOT 5
- Types not regonized on nodes HOT 4
- Note on mutation HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unist-util-visit.