Reputation: 5121
When you create empty Svelte component (eg. ComponentName.svelte
) like this:
<script>
export let segment;
</script>
<style>
</style>
<svelte:head>
<title>Lorem ipsum</title>
</svelte:head>
<p>lorem ipsum...</p>
you will have error:
<ComponentName> was created without expected prop 'segment'
Upvotes: 20
Views: 11297
Reputation: 555
As i am using TypeScript, I had to also define the type. This is what helped me:
export let anInstanceOfFoo: Foo | object = {};
Upvotes: 0
Reputation: 1514
Hacky solution to suppress all of these, use at your own risk:
+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);
};
}
Upvotes: -4
Reputation: 29615
This is to help you debug — you've defined a segment
prop, but the consumer of the component isn't giving it a value, which is likely to be the cause of bugs. Either the consumer should provide a value — <ComponentName segment="foo"/>
— or you should a) remove the prop, or b) give it a default value (which can be undefined
):
export let segment = undefined;
Any of those three actions will prevent the warning from appearing.
Upvotes: 42