-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instructions for augmented TypeScript typings
- Loading branch information
Showing
1 changed file
with
15 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -408,28 +408,37 @@ To generate a JavaScript file that can be used with a `<script>` element: | |
npm install --save-dev @types/chrome-remote-interface | ||
``` | ||
Note that the TypeScript definitions are automatically generated from the latest DevTools API, and therefore do not support the shorthand syntax available in this package for events. Also, methods without explicit parameters still require passing an empty object (`{}`). | ||
Note that the TypeScript definitions are automatically generated from the npm package `[email protected]`, and therefore do not support out-of-the-box the shorthand syntax available in this package for events. Also, methods without explicit parameters still require passing an empty object (`{}`). | ||
So for example, instead of: | ||
For example, the following are not supported directly: | ||
```js | ||
const {Network} = client; | ||
```ts | ||
const {Network, Page} = client; | ||
Network.requestWillBeSent((params) => { | ||
console.log(params.request.url); | ||
}); | ||
await Network.enable(); | ||
await Page.loadEventFired(); | ||
``` | ||
|
||
Use the following for TypeScript: | ||
There are 2 ways to resolve this: | ||
|
||
```js | ||
1. Use [augmented typings](https://github.com/kazarmy/devtools-protocol/tree/master/types) covering the above. They can be installed as follows: | ||
1. Install patch-package using [the instructions given](https://github.com/ds300/patch-package#set-up). | ||
2. Copy the contents of https://github.com/kazarmy/devtools-protocol/tree/master/types into `node_modules/devtools-protocol/types`. | ||
3. Run `npx patch-package devtools-protocol` so that the changes persist across an `npm install`. | ||
|
||
2. Use the following alternative syntax: | ||
|
||
```ts | ||
client['Network.requestWillBeSent']((params) => { | ||
console.log(params.request.url); | ||
}); | ||
|
||
await Network.enable({}); | ||
await client['Page.loadEventFired'](); | ||
``` | ||
|
||
[TypeScript]: https://www.typescriptlang.org/ | ||
|