/** * @license * Copyright 2024 Google Inc. * SPDX-License-Identifier: Apache-2.0 */ import {expectNotAssignable, expectNotType, expectType} from 'tsd'; import type {ElementHandle, JSHandle} from 'puppeteer'; declare const handle: JSHandle; { expectType(await handle.evaluate('document')); expectType( await handle.evaluate(() => { return 1; }) ); expectType( await handle.evaluate(() => { return document.body; }) ); expectType( await handle.evaluate(() => { return ''; }) ); expectType( await handle.evaluate((value, str) => { expectNotAssignable(value); expectType(str); return ''; }, '') ); } { expectType(await handle.evaluateHandle('document')); expectType>( await handle.evaluateHandle(() => { return 1; }) ); expectType>( await handle.evaluateHandle(() => { return ''; }) ); expectType>( await handle.evaluateHandle((value, str) => { expectNotAssignable(value); expectType(str); return ''; }, '') ); expectType>( await handle.evaluateHandle(() => { return document.body; }) ); } declare const handle2: JSHandle<{test: number}>; { { expectType>(await handle2.getProperty('test')); expectNotType>(await handle2.getProperty('test')); } { expectType>( await handle2.getProperty('key-doesnt-exist') ); expectNotType>( await handle2.getProperty('key-doesnt-exist') ); expectNotType>( await handle2.getProperty('key-doesnt-exist') ); } } { void handle.evaluate((value, other) => { expectType(value); expectType<{test: number}>(other); }, handle2); }