I am currently facing an issue wherein I am attempting to integrate chrome extension JavaScript code with TypeScript:
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
let result;
try {
[{ result }] = await chrome.scripting.executeScript({
target: { tabId: tab.id },
function: () => getSelection().toString(),
});
} catch (e) {
return;
}
console.log('Selection: ' + result);
};
The purpose of this code snippet is to log the user's selection upon clicking a button. However, when trying to incorporate this functionality into TypeScript, it results in a series of errors. The initial error encountered states
Property 'result' does not exist on type Property 'result' does not exist on type 'InjectionResult<unknown> | undefined'.
Various attempts have been made such as experimenting with the ! and ? operators, redirecting executeScript to a different function using func:
, and also declaring result as a regular variable. Unfortunately, these efforts have not led to a successful resolution. In fact, defining result as an ordinary variable raises another exception stating No overload matches this call.
at line 6.
How can I effectively address this issue? Furthermore, where can I locate a reference for the type InjectionResult?