Skip to content

Commit

Permalink
Merge pull request #69 from lino-levan/feat-infer-type-in-evaluate
Browse files Browse the repository at this point in the history
feat: infer return type in evaluate
  • Loading branch information
lino-levan authored May 23, 2024
2 parents 051780d + 786959d commit bf36cf6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class Page extends EventTarget {
async evaluate<T, R extends AnyArray>(
func: EvaluateFunction<T, R>,
evaluateOptions?: EvaluateOptions<R>,
): Promise<unknown> {
): Promise<T> {
if (typeof func === "function") {
const args = evaluateOptions?.args ?? [];
func = `(${func.toString()})(${
Expand All @@ -461,11 +461,14 @@ export class Page extends EventTarget {
}

if (result.type === "bigint") {
// @ts-ignore Only returns this value if T does
return BigInt(result.unserializableValue!.slice(0, -1));
} else if (result.type === "undefined") {
// @ts-ignore Only returns this value if T does
return undefined;
} else if (result.type === "object") {
if (result.subtype === "null") {
// @ts-ignore Only returns this value if T does
return null;
}
}
Expand Down

0 comments on commit bf36cf6

Please sign in to comment.