Skip to content

API to understand if component object has props #4649

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

Closed
ItalyPaleAle opened this issue Apr 8, 2020 · 6 comments
Closed

API to understand if component object has props #4649

ItalyPaleAle opened this issue Apr 8, 2020 · 6 comments
Labels
awaiting submitter needs a reproduction, or clarification feature request

Comments

@ItalyPaleAle
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Assume that component is a variable that contains a Svelte component class. For example:

import component from './Component.svelte`

It would be useful to have an API to get details on what props component exposes.

The reason for this is something that has appeared in svelte-spa-router recently. Starting with a recent version of Svelte, when using:

<svelte:component this="{component}" params="{componentParams}"  />

If the class of component does not export any params/props, Svelte now shows a warning.

However, I don't believe there's a way to know if component has props. I have found a workaround in the router, but that was not always ideal and has caused a couple of issues to users too.

Describe the solution you'd like

Would be great if component classes could export a list of properties (without their value). So, something like component.props being an array with the list of props exported.

How important is this feature to you?

After finding a workaround, some users of svelte-spa-router have been impacted with annoyances caused by this. For example ItalyPaleAle/svelte-spa-router#102

A better solution would require the upstream Svelte project to export that property.

@Conduitry
Copy link
Member

svelte.compile already exposes this information, but at a lower level (you have to actually be calling the compiler yourself). Adding this information as another named export from the compiled component sounds like it has the possibility of being a reasonable feature, but I don't like the idea of exposing it on the constructor itself or on instances, because that would be extra untreeshakable code that everyone would get whether they needed it or not.

If the goal of this is purely to avoid showing a runtime warning (and isn't needed for other functionality) I think we should try to consider other ways of dealing with the root issue. See also #4652, which has been opened for just this concern.

@ItalyPaleAle
Copy link
Contributor Author

Thanks a lot for the answer. I understand your point and yes, at least as of now, the issue is purely related to #4652 (can’t exclude that others will find different uses in the future, however).

@stale
Copy link

stale bot commented Dec 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Dec 24, 2021
@frederikhors
Copy link

Nope

@stale stale bot removed the stale-bot label Dec 24, 2021
@benrogmans
Copy link

I'd appreciate the requested solution as well, but indeed the root issue is the console warning during runtime, which make development a less joyful experience.

@dummdidumm dummdidumm removed the triage label Jan 19, 2024
@Rich-Harris
Copy link
Member

We removed the development warning from Svelte 5 (and possibly 4? can't remember) which solves the root issue — will close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification feature request
Projects
None yet
Development

No branches or pull requests

7 participants