//in first one I getting compNode from component. it's working fine. I'm able to create duplicate instance.
const compNode = figma.root.findOne(node => node.type == "COMPONENT_SET" && node.name == "post");
console.log(compNode,'compNode');
const postComponentSet = compNode as ComponentSetNode;
const defaultVarient= postComponentSet.defaultVariant as ComponentNode;
defaultVarient.createInstance();
//but 2nd option I getting selectedNode by selecting something on figma canvas
const selectedNode = figma.currentPage.selection[0];
console.log(selectedNode,'selected');
const postComponentSet2=selectedNode as ComponentSetNode;
const newNode = postComponentSet2.defaultVariant as ComponentNode;
newNode.createInstance();
//log of these two
Here the first case we got a ComponentSetNode and 2nd time we got InstanceNode
So my question is how can I convert the 2nd InstanceNode to ComponentSetNode?
Or is there any other way to createInstance of a selected portion/duplicate?