-
I have the following setup: A <script lang="ts">
import type { SubmitFunction } from '@sveltejs/kit' // Where to put the type?
import { enhance } from '$app/forms'
let {
children,
actionUrl = '',
submitFunction = () => {
return async ({ update }) => {
await update()
}
},
} = $props()
</script>
<form method="post" action={actionUrl} use:enhance={submitFunction}>
{@render children()}
</form> Now I get the following TS error when passing the function to My question is how to type the (The |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
They cannot be inferred because this is the left side of an assignment, the only thing that can be inferred is the type of the default values, which do not necessarily have anything to do with the values provided by whatever is on the right side of the assignment. The resulting type of the variables will be an intersection of both. I do not know of any way to avoid typing everything, the only minor optimization would be adding a utility type for So it's either of: let { ... }: {
children: Snippet,
actionUrl?: string,
submitFunction?: SubmitFunction,
} = $props();
let { ... }: HasChildren & {
actionUrl?: string,
submitFunction?: SubmitFunction,
} = $props(); |
Beta Was this translation helpful? Give feedback.
They cannot be inferred because this is the left side of an assignment, the only thing that can be inferred is the type of the default values, which do not necessarily have anything to do with the values provided by whatever is on the right side of the assignment.
The resulting type of the variables will be an intersection of both.
I do not know of any way to avoid typing everything, the only minor optimization would be adding a utility type for
{ children: Snippet }
.So it's either of: