'Forced symbol for the file with JSDoc `@name` returns an error that it does not exist

It is the code from the documentation (https://jsdoc.app/tags-name.html):

// @ts-check
/**
 * @name highlightSearchTerm
 * @function
 * @global
 * @param {string} term - The search term to highlight.
 */
 eval("window.highlightSearchTerm = function(term) {};")

 window.highlightSearchTerm("");

But it still returns an error:

Property 'highlightSearchTerm' does not exist on type 'Window & typeof globalThis'.ts(2339)

Live inline example - https://codesandbox.io/s/jsdoc-name-test-1u224k?file=/src/index.js (locally in VSCode there is the same error)

QUESTION: Why does @name not work? What should I replace it with?

My target code is supposed to be like this:

// @ts-check
/**
 * @name highlightSearchTerm
 * @function
 * @global
 * @param {string} term - The search term to highlight.
 */

 highlightSearchTerm("");

...because it's a function from another file, it uses in userScript, but so far even the version with window doesn't work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source