svelte-use-persist icon indicating copy to clipboard operation
svelte-use-persist copied to clipboard

TypeScript inference could be improved

Open fawaz-alesayi opened this issue 1 year ago • 0 comments

Currently, there are two ways to use this action:

  1. 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>
  1. 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

fawaz-alesayi avatar Mar 07 '23 10:03 fawaz-alesayi