dialog.ts

Declarations
#

4 declarations

view source

dialog_layouts
#

DialogLayout
#

DialogParams
#

dialog.ts view source

DialogParams<T>

This pattern is based on: https://github.com/ivanhofer/sveltekit-typescript-showcase/blob/main/src/01-props/09-svelte-component/Component.svelte The main limitation is that the generic cannot be inferred automatically, so we use to_dialog_params to construct instances in most cases. Definining DialogParams with no concrete T lacks typechecking for props.

generics

T

constraint Component<any>
default Component<any>

Component

type T

props

type ComponentProps<T>

dialog_props

type Partial<ComponentProps<typeof Dialog>> | undefined

to_dialog_params
#

dialog.ts view source

<T extends Component<any>>(Component: T, props: ComponentProps<T>, dialog_props?: Partial<Record<string, any>> | undefined): DialogParams<T>

This helper function is needed to construct DialogParams with type safety. It uses TypeScript's inferred generics for functions, which do not work for plain objects as of v5.0.4. * ContextmenuParams uses a similar strategy.

Component

type T

props

type ComponentProps<T>

dialog_props?

type Partial<Record<string, any>> | undefined
optional

returns

DialogParams<T>