Property "findAllWithCriteria" does not exist on type 'readonly SceneNode[]'. ts(2339) [11,47]

Hi there! I am trying to have my plugin determine whether or not the current selection contains text. I wrote the following code to do so:

const textNodes = figma.currentPage.selection.findAllWithCriteria({
types: [‘TEXT’]
})

if (textNodes.length > 0){
figma.ui.postMessage({ type: ‘text-selected’ })
}

However, I am getting the error stated in the question title. I decided to try just scanning the page instead, since this example was shown in the developers guide. So my new code is this:

const textNodes = figma.currentPage.findAllWithCriteria({
types: [‘TEXT’]
})

but I am still getting the error: Property ‘findAllWithCriteria’ does not exist on type ‘PageNode.’ ts(2339) [11,37]

What types can findAllWithCriteria be used on? Thank you!

Hey @Erica_Luzzi I think I was able to fix your issue. Add [0] after .selection. I’m not super savvy with code so I don’t really know why this fixes it, but it should. Hopefully someone else can help explain it!

So it should look like this:

const textNodes = figma.currentPage.selection[0].findAllWithCriteria({
types: [‘TEXT’]
})

if (textNodes.length > 0){
figma.ui.postMessage({ type: ‘text-selected’ })
}

@Erica_Luzzi

@Joey_Zingarelli,

By adding an array index of zero, the search for text nodes will only be in the first element of the array, not all of them.

1 Like

Thanks for the correction @tank666 ! Still learning :slight_smile: