[unist-util-filter] Typescript: Property 'type' does not exist on type 'Test<Node>' #29
-
Attempting to type a utility that removes frontmatter from markdown. Functions works as just JS, I just can't figure out how to add 'type' property to import filter from 'unist-util-filter'
import visit from 'unist-util-visit'
import type { Node } from 'unist'
import type { Test } from 'unist-util-is'
interface YamlNode extends Node {
type: string
}
export const removeFrontmatter = () => async (tree: Node, file) => {
let getFrontMatter
await visit(tree, 'yaml', (node) => {
getFrontMatter = node.data.parsedValue
return
})
file.data.frontmatter = getFrontMatter
return filter(tree, (node: Test<YamlNode>): node is YamlNode => node.type !== 'yaml')
// TS error here: Property 'type' does not exist on type 'Test<Node>' ^^^^^^^^
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A few different questions in here: 1 what is the input to a
|
Beta Was this translation helpful? Give feedback.
A few different questions in here: 1 what is the input to a
Test
accept? 2 why istype
missing? 3 what is a way to resolve this?what is the input to a
Test
accept?is known as a
Test
https://github.com/syntax-tree/unist-util-is#function-testnode-index-parent. A test may or may not receive a validnode
, as such it doesn't know what it's receiving andnode
is type unknown.a
Test
can also be null which checks that anode
is valid (but not it's type),string
which check that a node is valid and that node type matches the string passed in, or an object which checks that it matches passed in attributes.https://github.com/synt…