silverbulletmd / silverbullet

The knowledge tinkerer's notebook
https://silverbullet.md
MIT License
2.36k stars 169 forks source link

Add type guards in query functions #754

Closed Maks-s closed 7 months ago

Maks-s commented 7 months ago

As the user can type whatever they want as arguments, this PR changes the query functions' parameters' types to unknown and adds type guards to provide better exception handling.

Here's an example, using the following snippet

```template
{{replace(45, "4", "5")}}


**Without type guards**
![uh](https://github.com/silverbulletmd/silverbullet/assets/26678512/9b657c7e-6d7a-47d4-a02a-a336c93dc4cb)

**With type guards**
![nice](https://github.com/silverbulletmd/silverbullet/assets/26678512/f928b6b3-150a-44b6-aeeb-e95734a3e5b9)
zefhemel commented 7 months ago

Very nice, thank you!