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

"x was created without expected prop y" false alert with binding when prop = undefined #4457

Closed
pushkine opened this issue Feb 24, 2020 · 13 comments · Fixed by #6583
Closed
Labels

Comments

@pushkine
Copy link
Contributor

https://svelte.dev/repl/65985a2e42fe4b899a379750fe609447?version=3.19.1

<script>
	import Component from './Component.svelte'
	let value = undefined
</script>

<Component bind:value />

<Component> was created without expected prop 'value'

a fix for this would involve replacing a ton of test results so I'd suggest addressing #4454 at the same time

@Conduitry Conduitry added the bug label Jun 8, 2020
@crossjs
Copy link

crossjs commented Jul 5, 2020

I think this is not a bug, as let value = undefined; is the same as let value;.
Maybe we should support optional props.

@frederikhors
Copy link

frederikhors commented Aug 1, 2020

Same here.

This is very annoying to see warnings like these (and these).

@paulschreiber
Copy link

I had this code

  export let selection;

And got these warnings

 <Component> was created without expected prop 'selection'

Changing it to

 export let selection = "";

silenced the warnings.

@oatymart
Copy link

@paulschreiber it's not ideal because now your code is suggesting that selection always expects a string, which would be incorrect self-documenting code in all but a few cases.

@paulschreiber
Copy link

@oatymart what's the proper way to solve this?

@oatymart
Copy link

Use the appropriate default according to type for each of your props that deserves one, or continue to omit it if that makes more sense. Just don't expect to achieve perfection because it's all a tradeoff between warnings, readability, and convenience.

@stale
Copy link

stale bot commented Jun 26, 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.

@oneezy
Copy link

oneezy commented Mar 31, 2022

I'm having this issue popup as well

@Conduitry
Copy link
Member

This should be fixed in 3.51.0 - https://svelte.dev/repl/65985a2e42fe4b899a379750fe609447?version=3.51.0

@laztheripper
Copy link

Didn't have this warning before, and a lot of my components intentionally have many optional props. How do we remove this clutter from the console ?

@icjosh10
Copy link

This should be fixed in 3.51.0 - https://svelte.dev/repl/65985a2e42fe4b899a379750fe609447?version=3.51.0

I am having this issue today. Setting default values is not working either.

@icjosh10
Copy link

This should be fixed in 3.51.0 - https://svelte.dev/repl/65985a2e42fe4b899a379750fe609447?version=3.51.0

I am having this issue today. Setting default values is not working either.

Apologies, I had a component using an imported svelte component from node modules that I mistook the error as coming from my own "wrapper" component.

@hacktisch
Copy link

hacktisch commented Oct 19, 2023

Hacky solution to suppress all of these:

+layout.js

if (__SVELTEKIT_DEV__) {
    const warn = console.warn;
    console.warn = (...args) => {
        if (
            args.length === 1 &&
            /was created (with unknown|without expected) prop/.test(args[0])
        ) {
            return;
        }
        warn(...args);
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.