2024-02-05 09:26:37 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2024 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2022-07-06 07:05:37 +00:00
|
|
|
import {expectNotAssignable, expectNotType, expectType} from 'tsd';
|
2022-06-27 08:57:31 +00:00
|
|
|
|
2023-09-26 16:24:24 +00:00
|
|
|
import type {ElementHandle, JSHandle} from 'puppeteer';
|
2023-09-21 20:22:38 +00:00
|
|
|
|
2022-06-27 08:57:31 +00:00
|
|
|
declare const handle: JSHandle;
|
|
|
|
|
|
|
|
{
|
|
|
|
expectType<unknown>(await handle.evaluate('document'));
|
|
|
|
expectType<number>(
|
|
|
|
await handle.evaluate(() => {
|
|
|
|
return 1;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
expectType<HTMLElement>(
|
|
|
|
await handle.evaluate(() => {
|
|
|
|
return document.body;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
expectType<string>(
|
|
|
|
await handle.evaluate(() => {
|
|
|
|
return '';
|
|
|
|
})
|
|
|
|
);
|
|
|
|
expectType<string>(
|
|
|
|
await handle.evaluate((value, str) => {
|
|
|
|
expectNotAssignable<never>(value);
|
|
|
|
expectType<string>(str);
|
|
|
|
return '';
|
|
|
|
}, '')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
expectType<JSHandle>(await handle.evaluateHandle('document'));
|
|
|
|
expectType<JSHandle<number>>(
|
|
|
|
await handle.evaluateHandle(() => {
|
|
|
|
return 1;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
expectType<JSHandle<string>>(
|
|
|
|
await handle.evaluateHandle(() => {
|
|
|
|
return '';
|
|
|
|
})
|
|
|
|
);
|
|
|
|
expectType<JSHandle<string>>(
|
|
|
|
await handle.evaluateHandle((value, str) => {
|
|
|
|
expectNotAssignable<never>(value);
|
|
|
|
expectType<string>(str);
|
|
|
|
return '';
|
|
|
|
}, '')
|
|
|
|
);
|
|
|
|
expectType<ElementHandle<HTMLElement>>(
|
|
|
|
await handle.evaluateHandle(() => {
|
|
|
|
return document.body;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
declare const handle2: JSHandle<{test: number}>;
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
expectType<JSHandle<number>>(await handle2.getProperty('test'));
|
2022-07-06 07:05:37 +00:00
|
|
|
expectNotType<JSHandle<unknown>>(await handle2.getProperty('test'));
|
2022-06-27 08:57:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
expectType<JSHandle<unknown>>(
|
|
|
|
await handle2.getProperty('key-doesnt-exist')
|
|
|
|
);
|
2022-07-06 07:05:37 +00:00
|
|
|
expectNotType<JSHandle<string>>(
|
2022-06-27 08:57:31 +00:00
|
|
|
await handle2.getProperty('key-doesnt-exist')
|
|
|
|
);
|
2022-07-06 07:05:37 +00:00
|
|
|
expectNotType<JSHandle<number>>(
|
2022-06-27 08:57:31 +00:00
|
|
|
await handle2.getProperty('key-doesnt-exist')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-04-26 09:53:02 +00:00
|
|
|
void handle.evaluate((value, other) => {
|
2022-06-27 08:57:31 +00:00
|
|
|
expectType<unknown>(value);
|
|
|
|
expectType<{test: number}>(other);
|
|
|
|
}, handle2);
|
|
|
|
}
|