svelte-use-persist
svelte-use-persist copied to clipboard
TypeScript inference could be improved
Currently, there are two ways to use this action:
- Use it with a
key
the action will create and persist the store for you with that specific key
<form
use:persist={{
key: 'my-form'
}}
>
...
</form>
- Bring your own store. Form elements will save their values to your store.
<script>
let my_store = writable({})
</script>
<form
use:persist={{
store: my_store
}}
>
...
</form>
These two approaches are orthogonal. You are not supposed to use them at the same time. You either let the action manage the store, or you manage your own store.
Yet the current TypeScript code allows for this ambiguity:
<script>
let my_store = writable({})
</script>
<form
use:persist={{
key: "my-form"
store: my_store
}}
>
...
</form>
The current behavior is that it ignores the store
if there is a key
property. We can do better: TypeScript should yell if you pass both a key
and a store