Getting error: "Property 'hyperlink' does not exist on type 'TextNode'"

I am creating a custom Table of Contents app for my org.

I have an array of page nodes called section.
Here is my code:

section.forEach((name: string, id: number) => {
  let pageLink = figma.createText();

  pageLink.fontName = { family: fontName, style: "Regular" };
  pageLink.characters = name;
  pageLink.hyperlink = { type: "NODE", value: id };
  pageLink.textDecoration = "UNDERLINE";
  pageLink.fontSize = 16;

  sectionFrame.appendChild(pageLink);
});

When I remove the hyperlink, it works fine. When I don’t, the process fails and nothing is rendered to the page.

I have console logged name and id inside the loop and it returns good values.

From what I can see in the API docs (and other plugins) this is the correct syntax. Is there some other factor that causes hyperlink to not be available?

Could you clarify what your array of page nodes looks like?
Are you sure this line is correct: section.forEach((name: string, id: number) => {?
Also note that the hyperlink id must be a string, not a number.

Thanks for the response.

So what I’m trying to do is take the list of page nodes, and chunk them up into sub arrays (“sections”) based on a string prefix on some of the pages ("— ").

Here’s how I’m doing that. (I’m not a developer so this might look amateurish)

 let pages = [];
let pageIds = [];

figma.root.children.forEach((page) => {
      pages.push(page.name);
      pageIds.push(page.id);
});

const pageSections = [];
let sectionArray = [];

pages.forEach(page => {
  if (page.startsWith('--- ') && sectionArray.length !== 0) {
    pageSections.push(sectionArray);
    sectionArray = [];
  }
  sectionArray.push(page);
});

pageSections.push(sectionArray)

pageSections.forEach((section) => {
  createSectionItem(section)
})

It seems like this is where the problem is. How can I pass through the page ID to use for the hyperlink?

Update: Got it figured out. Here’s my new code…

  const newArray = [];
  let currArray = [];

  figma.root.children.forEach((page) => {
        if (page.name.startsWith('---') && currArray.length !== 0) {
          newArray.push(currArray);
          currArray = [];
        }
        currArray.push(page);
  });

  newArray.push(currArray)

  newArray.forEach((section) => {
      createSectionItem(section);
  });

createSectionItem loops through each “section” sub-array, which includes a list of nodes that have page.name and page.id so I’m able to create hyperlinks now.

Thanks again.

1 Like