Skip to content
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

Use generics for types where possible #1188

Closed
Cucumberrbob opened this issue Mar 21, 2023 · 3 comments · Fixed by #2021
Closed

Use generics for types where possible #1188

Cucumberrbob opened this issue Mar 21, 2023 · 3 comments · Fixed by #2021
Assignees
Labels
enhancement New feature or request feature request Request a feature or introduce and update to the project.

Comments

@Cucumberrbob
Copy link
Contributor

Describe what feature you'd like. Pseudo-code, mockups, or screenshots of similar solutions are encouraged!

Initially thought of this for the Autocomplete component, but after discussion on Discord, it seems this may be a more sweeping change.

Svelte has support for generic types. We can constrain them similar to <T extends S> in a generic:

type GenericType = $$Generic<{value: string}>;
export let selected: GenericType | undefined;

Now if we had a list of items of type B = { value: string; foo: Bar }, and the user sets bind:selected on the parent, the type of selected would be B, instead of just {value: string}

What type of pull request would this be?

Enhancement

Any links to similar examples or other references we should review?

No response

@Cucumberrbob Cucumberrbob added the feature request Request a feature or introduce and update to the project. label Mar 21, 2023
@endigo9740 endigo9740 added the enhancement New feature or request label Mar 21, 2023
@endigo9740
Copy link
Contributor

@ryceg I wanted to bring your attention to this as there may some overlap with what you're working through now.

@HugeLetters
Copy link
Contributor

Hi, may I work on this enhancement by any chance? I've stumbled upon this issue for Autocomplete component and I think I got it working with generics in like 2 minutes so I would love to issue a PR - can't say I would be capable of doing the same for other components tho but I may give it a try if you would like to.

@endigo9740
Copy link
Contributor

endigo9740 commented Sep 8, 2023

@HugeLetters of course, we always encourage help with outstanding issues like this. The only thing I'd encourage is not the keep the scope limited to only the Autocomplete component. I believe this issue for Modals is very much related:

Likewise, there may be other portions of Skeleton that could benefit from the user of generics as well.

Unfortunately I haven't had time personally to audit and find all locations where this might be relevant. So perhaps that would be a great place to start?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature request Request a feature or introduce and update to the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants