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
Add better Typescript support for modals #600
Comments
Thanks for bringing this to my attention @YummYume, yeah the Modal store was not quite up to par with Toasts and our upcoming Drawer updates. I've created this PR if you wish to test my improvements: Unfortunately we don't have a quick way to create a package tarball or allow you to install from a dev tag from NPM yet, so in the meantime I might recommend cloning down the Skeleton project itself and testing anywhere in the app. Create a new page or test directly on the existing Modals documentation page in: Routes > Inner > Utilities > Modals > +page.svelte But I'm seeing much improved IntelliSense here: I'll leave the PR open for a day or so to give you a chance to review. But otherwise I'd expect this to be merged and be part of the next release in about a week and a half. |
Hey @endigo9740, thanks for such a quick response (and work)! I've played around a bit with the However, I still think the <script lang="ts">
export let parent: ModalParent;
export let customAdditionalProp: string;
</script> |
@YummYume awesome glad to hear. Oh and thanks for reminding me about the parent prop, I meant to explain that. So yes, absolutely we can look to improve that now. But currently the way it's working is (hopefully) temporary as its very maintenance heavy. Essentially Svelte/Kit offers up a way to query all available parent prop values, however the API for this is not stable. Due to this if a prop is added or change in the parent, we have to add it to a separate object, and that object is then passed down to the child. Not the end of the world, but certainly leaves room for error. Adding a type would mean that we're now maintaining the props, the object, and now a new type that have to have all these changes stay in sync. So it does give me some pause. I'll review going ahead and setting it up though. But does seem fragile and prone to errors for future updates. But we'll see! |
@YummYume I feel like what we have now is a good step forward so I'm going to go ahead and merge this. It'll be part of the next release of course. Still trying to decide how I want to proceed on the parent props, but may be something we circle back to in the future. Suggestions are welcome! |
Describe what feature you'd like. Pseudo-code, mockups, or screenshots of similar solutions are encouraged!
Hello. Currently working with Skeleton again on a new project, I am thrilled to see how well it has grown and how amazing it is (it just works). However, I feel Typescript is currently not very well supported for some resources and is crucial for a good dev experience.
Let's take an example with a simple custom modal, which I have mostly just copy-pasted from the docs :
Here we already have a few issues, such as
modalStore
being typed asany
, requiring disabling eslint while not providing any IntelliSense.In my
Modal.svelte
, I cannot access my props with typing (although that's not the most annoying), but I also have to type theparent
prop as eitherany
orRecord
to avoid having errors on my parent type (like when callingparent.onClose
). And again, it does not provide any IntelliSense, and I feel like it really should.I have not yet tested all of the different components available, so I can't say for sure about the status of Typescript support for the rest of this library.
What type of pull request would this be?
Enhancement
Any links to similar examples or other references we should review?
If we take for example a SvelteKit app with a
+page.server.ts
page where I export some data, then I can fully access them in my+page.svelte
by simply typing mydata
prop withPageData
.Taken directly from the SvelteKit doc
Although this is just an example of how it could look, I still feel like some parts need improvement to provide better Typescript support and provide at least a basic IntelliSense.
The text was updated successfully, but these errors were encountered: