-
- Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Is your feature request related to a problem? Please describe.
Take this simple store as an example:
import { readable, Readable } from 'svelte/store'; const store: Readable<string> = readable('', (set) => { helper(set); }) function helper(set) { set('test'); }
The problem is that I can't type helper
's argument and return types because there are some internal Svelte types that are not exported:
/** Callback to inform of a value updates. */ type Subscriber<T> = (value: T) => void; /** Unsubscribes from value updates. */ type Unsubscriber = () => void;
This applies to many other internal types in svelte/store
, too, ie. The below is not exported:
/** Start and stop notification callbacks. */ type StartStopNotifier<T> = (set: Subscriber<T>) => Unsubscriber | void;
Describe the solution you'd like
I would like to be able to write:
function helper(set: Subscriber<string>): Unsubscriber | void { set('test'); }
The same would apply to other features of Svelte, too.
This means Svelte would have to export (almost) all of its Typescript definitions in svelte/store
Describe alternatives you've considered
I've looked at Type Inference but that's fairly inconvenient for dev. I'd prefer to directly use Svelte's internal type definitions.
How important is this feature to you?
I'm looking for a way to use Typescript with Svelte efficiently. This would help a lot with using Typescript in Svelte.
Additional context
Note that I haven't used Svelte a lot. There are maybe better Typescript practices for this Svelte use case that someone can advise?