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

Add helper types to extract props a component accepts #7584

Closed
dummdidumm opened this issue Jun 4, 2022 · 0 comments · Fixed by #6770
Closed

Add helper types to extract props a component accepts #7584

dummdidumm opened this issue Jun 4, 2022 · 0 comments · Fixed by #6770

Comments

@dummdidumm
Copy link
Member

dummdidumm commented Jun 4, 2022

Describe the problem

sveltejs/language-tools#442 (comment) and a similar post above in that thread shows that people want to have a way to get the prop a component expects from its definition. This requires internal knowledge of the class interface which is brittle and might break for people (it's not regarded as public API). We therefore should add a convenience type that does this for us.

Describe the proposed solution

type ComponentProps<T> = T extends new (...args: any[]) => SvelteComponentTyped<infer Props> ? Props : unknown // or never, or any?

Alternatives considered

none

Importance

would make my life easier

dummdidumm pushed a commit to dummdidumm/svelte that referenced this issue Jun 28, 2022
dummdidumm added a commit that referenced this issue Jul 1, 2022
ComponentType eases typing "this is a variable that expects a Svelte component constructor (of a certain shape)". Removes the need for SvelteComponentTyped to be an extra type so it can be deprecated in v4 and removed in v5, and SvelteComponent(Dev) can receive the same generic typings as SvelteComponetTyped in v4.

ComponentProps eases typing "give me the props this component expects". Closes #7584


Co-authored-by: Simon Holthausen <simon.holthausen@accso.de>
Co-authored-by: Hofer Ivan <ivan.hofer@outlook.com>
Co-authored-by: Ignatius Bagus <ignatius.mbs@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant