I am trying to make chrome extension js code work 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);
};
This logs user's selection on click of a button. However, when trying to work with this in typescript, it throws a cascade of errors at me.
The first one is Property 'result' does not exist on type Property 'result' does not exist on type 'InjectionResult<unknown> | undefined'.
I have tried fiddling around with ! and ? operators, sending executeScript to a different function via func: but have not been able to get this to a working state. I also tried to make result and ordinary variable, but in this case No overload matches this call. exception is thrown on line 6.
How do I go about resolving this? Also, can I find type reference for InjectionResult anywhere?