puppeteer/src
Jack Franklin 29ebd0bb3e
chore: migrate src/ExecutionContext (#5705)
* 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.
2020-04-22 10:33:44 +01:00
..
.eslintrc.js chore: move code to src/ and emit with TypeScript (#5568) 2020-04-02 16:25:19 +02:00
Accessibility.js chore: migrate src/JSHandle to TS (#5703) 2020-04-21 12:11:06 +01:00
api.js chore: move code to src/ and emit with TypeScript (#5568) 2020-04-02 16:25:19 +02:00
Browser.js chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
BrowserFetcher.js chore(deps): update extract-zip to version 2 (#5610) 2020-04-09 21:13:25 +02:00
Connection.ts chore: migrate src/helpers.ts to ESM (#5699) 2020-04-21 10:22:20 +01:00
Coverage.ts chore: migrate src/coverage to TypeScript (#5702) 2020-04-21 11:45:29 +01:00
DeviceDescriptors.ts chore(eslint): add eslint typescript linting (#5635) 2020-04-14 12:08:52 +01:00
Dialog.ts chore: migrate src/helpers.ts to ESM (#5699) 2020-04-21 10:22:20 +01:00
DOMWorld.js chore: migrate src/ExecutionContext (#5705) 2020-04-22 10:33:44 +01:00
EmulationManager.js chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
Errors.js chore: move code to src/ and emit with TypeScript (#5568) 2020-04-02 16:25:19 +02:00
Events.js chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
ExecutionContext.ts chore: migrate src/ExecutionContext (#5705) 2020-04-22 10:33:44 +01:00
externs.d.ts chore: migrate src/ExecutionContext (#5705) 2020-04-22 10:33:44 +01:00
FrameManager.js chore: migrate src/JSHandle to TS (#5703) 2020-04-21 12:11:06 +01:00
helper.ts chore: migrate src/ExecutionContext (#5705) 2020-04-22 10:33:44 +01:00
Input.js chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
JSHandle.ts chore: migrate src/ExecutionContext (#5705) 2020-04-22 10:33:44 +01:00
Launcher.js chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
LifecycleWatcher.js chore: move code to src/ and emit with TypeScript (#5568) 2020-04-02 16:25:19 +02:00
NetworkManager.js chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
Page.js chore: migrate src/JSHandle to TS (#5703) 2020-04-21 12:11:06 +01:00
PipeTransport.ts chore: migrate src/helpers.ts to ESM (#5699) 2020-04-21 10:22:20 +01:00
promisify.ts chore: migrate src/helper to typescript (#5689) 2020-04-20 12:02:32 +01:00
protocol.d.ts chore: move code to src/ and emit with TypeScript (#5568) 2020-04-02 16:25:19 +02:00
Puppeteer.js fix: set revision based on PUPPETEER_PRODUCT (#5643) 2020-04-15 13:30:42 +02:00
Target.js chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
TaskQueue.ts chore: enforce consistent spacing around object curlys (#5700) 2020-04-21 10:40:04 +01:00
TimeoutSettings.ts chore: migrate src/timeoutsettings to typescript (#5691) 2020-04-20 11:32:08 +01:00
Tracing.js chore: migrate src/Connection to TypeScript (#5694) 2020-04-21 09:20:25 +01:00
USKeyboardLayout.ts chore: migrate src/USKeyboardLayout to typescript (#5695) 2020-04-21 10:21:45 +01:00
WebSocketTransport.ts chore: migrate src/WebSocketTransport to TypeScript (#5696) 2020-04-21 08:45:52 +02:00
Worker.js chore: migrate src/Connection to TypeScript (#5694) 2020-04-21 09:20:25 +01:00