Skip to content

Commit

Permalink
docs: add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamiell committed Nov 19, 2023
1 parent 0be6d5a commit d2425fa
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ logger.info("foo: %s", foo);

In this case, `%s` refers to a string, as explained in the [documentation for logging method parameters](https://getpino.io/#/docs/api?id=logger).

If you use a string interpolation placeholder without a corresponding argument or with an argument of the wrong type, the TypeScript compiler will throw an error. For example:

```ts
const foo: string = getFoo();
logger.info("foo: %s"); // Error: Missing an expected argument.
logger.info("foo: %d", foo); // Error: `foo` is not a number.
```

## Validating the Object

Pino supports [logging both strings and objects](https://getpino.io/#/docs/api?id=logger). If you are passing an object to a Pino logger, you might want to validate that the object is in the correct shape. You can do this with the [`satisfies` operator](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html) in the same way that you would in other kinds of TypeScript code. For example:
Expand Down

0 comments on commit d2425fa

Please sign in to comment.