Skip to content

A way to forgive unused props, without the compiler or browser screaming at you #5892

Closed
@arnu515

Description

@arnu515

I don't really know if this is supposed to be a bug report or a feature request, but I chose feature request. LMK if changes are required.

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:

<!-- App.svelte -->
<script lang=ts>
    import Test from "./test.svelte"
</script>

<Test prop1={123} prop2={["an array"]} prop3="lorem ipsum" prop4={{a: "b"}} />
<!-- test.svelte -->
<script lang=ts>
    // I want to use prop1, but not prop2, prop3 or prop4
    export let prop1: number;

    // Example 1: Using "export let prop2" without usage
    export let prop2: any;
    // This will make the compiler say that the variable was defined without usage

    // Example 2: Using "export const prop3 = defaultValue", like the compiler suggests
    export const prop3 = "hello world";
    // This makes the browser console scream at you (see screenshot)

    // Finally, if I choose to not put any export, the browser will still scream at me
</script>

<h1>{prop1}</h1>

Screenshot showing the browser not liking export const
Screenshot 2021-01-17 at 8 47 39 PM

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 info

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions