Basically, if need a prop to be optional, you need to assign it a value when defined instead of using let value?: string
<script lang="ts">
export let someProp: string // Required prop
export let someOtherProp: string = "hello" // Optional prop
</script>
interface BlogPost {
status: "ACTIVE" | "HIDDEN"
}
const post = writable<BlogPost>({
status: 'ACTIVE',
})
To type an expected store, like passing a store as a prop, you would use the Writable generic type.
import type { Writable } from 'svelte/store';
export let data: Writable<BlogPost>
const dispatch = createEventDispatcher<{ nameOfEvent: { passedProperties: any } }>()
here is the same thing with real code.
const dispatch = createEventDispatcher<{ toggle: { isToggled: boolean } }>()
// Now I'm typed!
dispatch('toggle', {
isToggled,
})
This is not currently supported.
For now, see: https://www.swyx.io/jsdoc-swyxkit/