Skip to main content

So, every time I click a component on the screen, the node gets detected via this evenetData?.node method. I save it as a SceneNode. Later I want to access the node.children Property. The compiler however says that the node might not have that attribute, and marks it as an error. The program runs fine, however it’s quite annoying to always have 10+ errors in your file. Had anyone ever had a similar problem?


const node: SceneNode = eventData?.node;



function getAllNodes(node: SceneNode, arrayWrapper: { data: stringn] }) {
if(node.children){
for(let i = 0; i < node.children.length; i++){
getAllNodes(node.childrenei], arrayWrapper);
}
}
else{
if(node.type === "TEXT") arrayWrapper.data.push(node.characters);
if(node.type === "VECTOR") arrayWrapper.data.push(node.parent.name);
}
}

Check out this explanation: Get all nodes that are red - #4 by Gleb


Thank you, but I already tried that. That solution works fine for “children” in node, but for some reason it does not work for node.parent.name. I mean, I can check if parent in node, but the squiggly lines stay


EDIT: I figured it out. you have to check


if(node.parent) {
if("name" in node.parent){
//code
}
}

Reply