Repository navigation
[@types/chrome], devtools.inspectedWindow.eval return type incorrect #75484
|
The current type definition for https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/chrome/index.d.ts#L2935 function eval<T = { [key: string]: unknown }>(
expression: string,
options?: EvalOptions,
): Promise<{ result: T; exceptionInfo: EvaluationExceptionInfo }>;However, running the following in either background-page or inside a devtools-panel: chrome.devtools.inspectedWindow.eval('5').then(console.log);Logs the number 5 to console, and not Running chrome.devtools.inspectedWindow.eval('throw new Error(`test`)').then(console.log, console.warn);Results in a console-warning As such, the type should actually be function eval<T>(
expression: string,
options?: EvalOptions,
): Promise<T>;When using the callback variant of inspectedWindow.eval: So I think the full type should probably be function eval<T>(
expression: string,
options?: EvalOptions,
): Promise<T>;
function eval<T>(
expression: string,
callback?: (result?: T, exceptionInfo?: EvaluationExceptionInfo) => void,
): void;
function eval<T>(
expression: string,
options: EvalOptions | undefined,
callback?: (result?: T, exceptionInfo?: EvaluationExceptionInfo) => void,
): void;I think technically it might be more correct for the callback to be typed as ((result: T) => void) | ((result: undefined, exceptionInfo: EvaluationExceptionInfo) => void)Depending on how precise you want the types |
Replies: 2 comments 3 replies
|
Thanks for the discussion about " Pinging the DT module owners: @matthewkimber, @otiai10, @sreimer15, @matcarlson, @ekinsol, @EchoAbstract, @spasma, @bdbai, @JasonXian, @userTim, @idan315, @nicolas377, @idosal, @fregante, @erwanjugand. |
|
You're right, the promise's type is directly the response. Additionally, I think the Unless you'd like to contribute, I'll try to fix this in the coming days :) |

Related at #75497 (@wimbarelds, @nicolas377)