Skip to content

Commit

Permalink
docs(nice-grpc): Add example to docs for extending a client Type with…
Browse files Browse the repository at this point in the history
… CallOptions (#426)
  • Loading branch information
matt-de-young authored Aug 31, 2023
1 parent 67db8ca commit 191e706
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/nice-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,15 @@ const client2 = clientFactory.use(middlewareC).create(Service2, channel2);
In the above example, `Service1` client gets `middlewareA` and `middlewareB`,
and `Service2` client gets `middlewareA` and `middlewareC`.

Type augmentation to `Client` CallOptions is done automatically by adding a middleware, but can also be done by passing a generic. This code example shows how to correctly annotate client type given that middleware has type `ClientMiddleware<{callOption?: number}>`.

```ts
let client: ExampleServiceClient<{callOption?: number}>;
client = createClientFactory()
.use(middleware)
.create(ExampleService, channel);
```

##### Example: Logging

Log all calls:
Expand Down

0 comments on commit 191e706

Please sign in to comment.