Type of parts of the AST in Typescript unclear #51
-
After getting a chunk (an array of nodes, to be clear) of nodes with
and got
then I asserted that chunk
then I asserted it
and got the same again...
So, how I can I deal with AST chunks with TS? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Think I found the correct type for that chunk embedded into a Root type: |
Beta Was this translation helpful? Give feedback.
-
Hm, |
Beta Was this translation helpful? Give feedback.
-
Ok, I saw in some of the docs that I should import Btw, and re |
Beta Was this translation helpful? Give feedback.
-
@lkj4 this incompatibility is likely coming from
a few options: In the meantime, you may want to checkout https://unifiedjs.com/learn/guide/syntax-trees-typescript/ and https://unifiedjs.com/learn/recipe/narrow-node-typescript/ which introduce the unified syntax trees and some of the approaches to getting the specific types. |
Beta Was this translation helpful? Give feedback.
@lkj4 this incompatibility is likely coming from
https://github.com/mrzmmr/unist-util-find-all-between/blob/adb9565a4424bcd9bcd3db4199b4d15ba91c6ecb/types/index.d.ts#L16-L21
remark-*
plugins expect to get mdast nodes, this is returning a list more generic unistNode
, which doesn't have the properties generally expected on mdast.a few options:
1, open an issue (or even better a PR) with https://github.com/mrzmmr/unist-util-find-all-between to add generics and type narrowing so it can figure out the type it is passed.
2. share a sample of the code you are trying, so folks can offer more concrete suggestions on what to do
In the meantime, you may want to checkout https://unifiedjs.com/lear…