-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the problem
There's times when the same interface you're using for a component's props, is used in multiple other places in the application.
I hate that you can't use interfaces with Svelte props, since you have you declare props one by one. Example:
export let count: number = 0
export let name: string = ''It would be nice if you could pass in interfaces, like the following:
interface Props {
count: number
name: string
}Obviously a contrived example, as the type can be inferred, but please ignore that for this sake.
Describe the proposed solution
Something like Vue 3 Reactivity Transform (which incidentally won't be supported natively to destructure, despite being an experimental feature):
interface Props {
count: number
name: string
}
const { count = 0, name = '' } = defineProps<Props>()The interface would then control whether or not a prop is optional, like so:
interface Props {
count?: number
name?: string
}Alternatives considered
I'm not aware of any alternatives that currently exist to solve this issue. It's one of the rare things I feel like Svelte is lacking, which is an otherwise delightful library to use.
Importance
would make my life easier