import {type ElementHandle, type JSHandle} from 'puppeteer'; import {expectNotAssignable, expectNotType, expectType} from 'tsd'; 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); }