Skip to content

Commit

Permalink
Add instructions for augmented TypeScript typings
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored and cyrus-and committed Sep 21, 2022
1 parent a2a31cf commit cbd690f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit cbd690f

Please sign in to comment.