-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Custom Type in persist() which accepts any[] #19
Comments
The resulting type of So the right line is: Let's write a bit more code (this is exactly the same result as before):type listOfHuman = Array<hunanType> // The type of the data
const humansStore: Writable<listOfHuman> = writable([]); // The base store
const humans: PersistentStore<listOfHuman> = persist(humansStore, localStorage(), 'humans')` // Add the persist feature And now some explanation (for the sake of readability, some parameter have been altered):
The subtype allow to have a class/interface/function that can be specialized at runtime. So to use PersistentStore, we have to match The goal is to have a persistant store that contains a list of
|
Wow, This is a very in-depth explanation, I have added 'Learn TypeScript' into my PRD for this year, and so far I've got variables down, but the rest looks very bad to read... I have been told that it is very good once you learn it properly, but I find that extremely hard to be easily readable, it does not look like clear concise code at all, but maybe that's just me. This code line doesn't error anymore, and after reading it a few more times it does make sense. I was not aware of the 'PersistentStore' type, it wasn't in the documents anywhere that I can see. |
You are right, the static documentation have most its examples (all svelte code) in plain JS and not in TypeScript. And the generated documentation ( I will update the README to at least list the exposed interface/type |
So I've started learning and transitioning to .TS because it appears as though that is a good thing. But I'm having a hard time translating some components and helpers to TS... particularly this svelte-persistent-store.
I have a class Store, with a constructor, with all my publics. ... as follows.
I started to write a custom Interface called humanType, to use instead of the default, string/object/number, etc...
But now that line errors...
Type PersistentStore<any[]> is not assignable to type Writeable
Is this a matter of how svelte-persistent-store is written, or how Writable in svelte/store is written, or a combination of the two... I'm not familiar enough with .TS to figure out what I've done here.
The text was updated successfully, but these errors were encountered: