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
I think this is not a bug, as let value = undefined; is the same as let value;.
Maybe we should support optional props.
Same here.
This is very annoying to see warnings like these (and these).
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.
@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.
@oatymart what's the proper way to solve this?
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.
Most helpful comment
I think this is not a bug, as
let value = undefined;is the same aslet value;.Maybe we should support optional props.