Skip to content

Commit

Permalink
docs(xml): write a tip on enhanced type safety
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Jul 1, 2024
1 parent 358f9ce commit 51747bc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions xml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ stringify({
Note that while you can theorethically use internal API properties, we strongly advise against it currently. Supporting `~children` might be added in the future ([#57](https://github.com/lowlighter/libs/issues/57)) for mixed content, but its behavior is not well defined yet.
Setting `~name` manually might lead to unexpected behaviors, especially if it differs from the parent key.

> [!TIP]
> For more type-safety, write `satisfies Partial<xml_document>` after whatever you pass into `stringify`, like so:
>
> <!-- TODO(lishaduck): Add ts highlighting once denoland/deno#24164 is resolved -->
>
> ```
> import { stringify, type xml_document } from "./stringify.ts"
>
> const ast = {
> "@version": "1.0",
> "@encoding": "UTF-8",
> "root": {},
> } satisfies Partial<xml_document>
> const result = stringify(ast)
> ```
>
> We expose lax typing, but `Partial<xml_document>` uses the stricter typing we use internally.
## 📜 License and credits

```
Expand Down

0 comments on commit 51747bc

Please sign in to comment.