mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
29ebd0bb3e
* chore: migrate src/ExecutionContext to TypeScript I spent a while trying to decide on the best course of action for typing the `evaluate` function. Ideally I wanted to use generics so that as a user you could type something like: ``` handle.evaluate<HTMLElement, number, boolean>((node, x) => true, 5) ``` And have TypeScript know the arguments of `node` and `x` based on those generics. But I hit two problems with that: * you have to have n overloads of `evaluate` to cope for as many number of arguments as you can be bothered too (e.g. we'd need an overload for 1 arg, 2 args, 3 args, etc) * I decided it's actually confusing because you don't know as a user what those generics actually map to. So in the end I went with one generic which is the return type of the function: ``` handle.evaluate<boolean>((node, x) => true, 5) ``` And `node` and `x` get typed as `any` which means you can tell TS yourself: ``` handle.evaluate<boolean>((node: HTMLElement, x: number) => true, 5) ``` I'd like to find a way to force that the arguments after the function do match the arguments you've given (in the above example, TS would moan if I swapped that `5` for `"foo"`), but I tried a few things and to be honest the complexity of the types wasn't worth it, I don't think. I'm very open to tweaking these but I'd rather ship this and tweak going forwards rather than spend hours now tweaking. Once we ship these typedefs and get feedback from the community I'm sure we can improve them. |
||
---|---|---|
.. | ||
.eslintrc.js | ||
Accessibility.js | ||
api.js | ||
Browser.js | ||
BrowserFetcher.js | ||
Connection.ts | ||
Coverage.ts | ||
DeviceDescriptors.ts | ||
Dialog.ts | ||
DOMWorld.js | ||
EmulationManager.js | ||
Errors.js | ||
Events.js | ||
ExecutionContext.ts | ||
externs.d.ts | ||
FrameManager.js | ||
helper.ts | ||
Input.js | ||
JSHandle.ts | ||
Launcher.js | ||
LifecycleWatcher.js | ||
NetworkManager.js | ||
Page.js | ||
PipeTransport.ts | ||
promisify.ts | ||
protocol.d.ts | ||
Puppeteer.js | ||
Target.js | ||
TaskQueue.ts | ||
TimeoutSettings.ts | ||
Tracing.js | ||
USKeyboardLayout.ts | ||
WebSocketTransport.ts | ||
Worker.js |