mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
f42336cf83
This PR moves the puppeteer source code into separate mono-repo packages: - `puppeteer` and `puppeteer-core` are now separated into their own packages. - `puppeteer-core` has a new exports called `puppeteer-core/internal` for internal usage. Tests and various tools have been updated to accommodate the migration.
84 lines
1.8 KiB
TypeScript
84 lines
1.8 KiB
TypeScript
import {ElementHandle, JSHandle} from 'puppeteer';
|
|
import {expectNotAssignable, expectNotType, expectType} from 'tsd';
|
|
|
|
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'));
|
|
expectNotType<JSHandle<unknown>>(await handle2.getProperty('test'));
|
|
}
|
|
{
|
|
expectType<JSHandle<unknown>>(
|
|
await handle2.getProperty('key-doesnt-exist')
|
|
);
|
|
expectNotType<JSHandle<string>>(
|
|
await handle2.getProperty('key-doesnt-exist')
|
|
);
|
|
expectNotType<JSHandle<number>>(
|
|
await handle2.getProperty('key-doesnt-exist')
|
|
);
|
|
}
|
|
}
|
|
|
|
{
|
|
handle.evaluate((value, other) => {
|
|
expectType<unknown>(value);
|
|
expectType<{test: number}>(other);
|
|
}, handle2);
|
|
}
|