-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
A way to forgive unused props, without the compiler or browser screaming at you #5892
Comments
Just do |
@dummdidumm @Conduitry Please reopen this issue |
Sorry I misread your text. Turning this off is indeed not possible right now if I remember correctly. You can disable certain warnings by doing So it would be good if this worked: // svelte-ignore unused-export-let
export let params; |
Thanks! I'll be using this for now, but an official fix will be appreciated :) EDIT: I'm sorry to say @dummdidumm, but this doesn't work for |
What's the point of passing a prop to a component that is not used? Looks like a code smell to me. EDIT: I just read your Gist. If you go through the trouble to set up your own PageJS instance and rebuild a Svelte router from scratch. Why not also conditionally pass the query & params props when they're actually filled? |
I don't know how to do that, maybe something like this: {#if query}
<Component {query} />
{:else}
<Component />
{/if} But then what will I do on the component's end? I'm guessing |
Yes I know, that's why I said |
Oh right! Didn't read the would. Do you have a new solution? |
No there is no solution currently that I know of. Well... You could try |
Yes that will work, but an official fix is suggested :) |
I know you requested te option to silence the warnings. So this might not be good enough. I'm trying anyhow. But what about a export let params: Object;
export let query: Object; In the router setup it could look a little like this: <script>
let props = {};
function setProps(params: Object, query: Object) {
const newProps = {};
if(Object.keys(params).length > 0) {
newProps.params = params
}
if(Object.keys(query).length > 0) {
newProps.query = query
}
props = newProps;
}
</script>
<svelte:component {...props} /> |
I'll try using this for now, and I'll also redo the router code. Thanks everybody for the help! I really hope that my request does get fulfilled, i.e. there'll be a way to silence the warnings in the future, but I got what I wanted. Any moderators/members can close this issue if they want to :) |
My own example: |
This is a little unrelated, but you specify a contract for the custom component, right? Svelte is explicit. So if your contract states that you'll pass the column & row data as a prop, then the implementing component needs to list those two props for usage. If the component then does not use the data, that's fine, at least it did not forget to implement anything from the contract. EDIT: I see your point now. assigning the prop to something like And what about a slot setup along the lines of |
I created an RFC to solve this issue, if anyone is interested. |
You could use the magic <script lang="ts">
// ...
const props = $$props;
</script> The If you're never going to use these props, things will hush by just adding the following: <script lang="ts">
// ...
$$restProps;
</script> |
I would like official support for this too. The context for me for add a property that is not used direct is to add better TypeScript support for my component. I want a property to be a key of an object however to know what the valid keys, I need to pass in the object (even thought the object itself is not needed directly by the component). |
Is your feature request related to a problem? Please describe.
If we have a component that we have provided props for, but don't want to use some of the props like the example shown below, there's no way to ignore the props without either the compiler or the browser screaming at you:
Screenshot showing the browser not liking
export const
Describe the solution you'd like
I would like
export const
to make the browser not scream at me.Describe alternatives you've considered
None. I've just ignored the error
How important is this feature to you?
Not very important, but I would love to see it fixed
Additional context
I'm using this for routes using pagejs, where the prop
params
can be undefined, so please don't suggest "You should just use all props or not provide unnecessary props", because I'm doing this using the<svelte:component>
component. See this github gist for more infoThe text was updated successfully, but these errors were encountered: