Incorrect types
o-az opened this issue · comments
Property 'children' does not exist on type 'Node<Data>'.ts
The Node
type is the following (from hast
which exports it from uinst
):
export interface Node<TData extends object = Data> {
type: string;
data?: TData | undefined;
position?: Position | undefined;
}
In here the usage example has node.children
and node.properties
but neither children nor properties
are properties of type Node
.
I think it should be Element
not Node
:(
@atomiks I think I found another issue.
Property 'properties' does not exist on type 'ElementContent'.
Property 'properties' does not exist on type 'Comment'.ts(2339)
This is happening in child.properties.style
:
The Element['children']
type is ElementContent[]
and ElementContent
type is:
type ElementContent = ElementContentMap[keyof ElementContentMap];
and ElementContentMap
type doesn't have properties
property.
Thank you for your attention. Consider adding a linting step in CI. I would be happy to contribute that!
Yeah that would definitely be the best idea. Prior to 0.9.6 they just had any
types, but adding the stricter types requires a lot more work/testing to make sure everything's good.
I believe this is expected, as in this case you need to use a type guard to verify that the child is an Element
node, and not something like a Text
node. Something like this works:
import type {Element} from 'hast';
function isElement(value: any): value is Element {
return value ? value.type === 'element' : false;
}