GoogleChrome / GoogleChrome/chrome-types
`chrome.scripting.executeScript`: `func` with `args` throws error
- Dominant language
- JavaScript
- Stars
- 274
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Description
I tried to execute
```js
await chrome.scripting.executeScript({
target: {tabId: tab.id},
func: (text) => {
(document.activeElement! as HTMLInputElement).value += (text || '');
},
args: [text],
});
```
and TypeScript tells me
```
TS2769: No overload matches this call.
Overload 1 of 2, '(injection: ScriptInjection): Promise', gave the following error.
Type '(text: any) => void' is not assignable to type '() => void'.
Target signature provides too few arguments. Expected 1 or more, but got 0.
Overload 2 of 2, '(injection: ScriptInjection, callback?: ((results: InjectionResult[]) => void) | undefined): void', gave the following error.
Type '(text: any) => void' is not assignable to type '() => void'.
```
as well as
```
TS7006: Parameter 'text' implicitly has an 'any' type.
```
the type definition looks a bit too simple compared to @types/chrome
```ts
export interface ScriptInjection {
func?: () => void;
args?: any[];
...
}
```
```ts
export type ScriptInjection = {
target: InjectionTarget;
world?: ExecutionWorld;
injectImmediately?: boolean;
} & ({
files: string[];
} | ({
func: () => Result;
} | {
func: (...args: Args) => Result;
args: Args;
}))
```
Following might also be a separate issue, but maybe add to the docs that one has to add `/// ` to a `.d.ts`since at least for me, it didn't take it automatically.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.