Skip to content

Commit bd3596f

Browse files
committed
feat: Define the MountOptions type
1 parent 0598f2b commit bd3596f

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

packages/svelte/types/index.d.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -379,26 +379,44 @@ declare module 'svelte' {
379379
}): Snippet<Params>;
380380
/** Anything except a function */
381381
type NotFunction<T> = T extends Function ? never : T;
382-
/**
383-
* Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component.
384-
* Transitions will play during the initial render unless the `intro` option is set to `false`.
385-
*
386-
* */
387-
export function mount<Props extends Record<string, any>, Exports extends Record<string, any>>(component: ComponentType<SvelteComponent<Props>> | Component<Props, Exports, any>, options: {} extends Props ? {
382+
export type MountOptions<Props extends Record<string, any> = Record<string, any>> = {
383+
/**
384+
* Target element where the component will be mounted.
385+
*/
388386
target: Document | Element | ShadowRoot;
387+
/**
388+
* Optional node inside `target` and when specified, it is used to render the component immediately before it.
389+
*/
389390
anchor?: Node;
390-
props?: Props;
391+
/**
392+
* Allows the specification of events.
393+
*/
391394
events?: Record<string, (e: any) => any>;
395+
/**
396+
* Used to define context at the component level.
397+
*/
392398
context?: Map<any, any>;
399+
/**
400+
* Used to control transition playback on initial render. The default value is `true` to run transitions.
401+
*/
393402
intro?: boolean;
403+
} & {} extends Props ? {
404+
/**
405+
* Component properties.
406+
*/
407+
props?: Props;
394408
} : {
395-
target: Document | Element | ShadowRoot;
409+
/**
410+
* Component properties.
411+
*/
396412
props: Props;
397-
anchor?: Node;
398-
events?: Record<string, (e: any) => any>;
399-
context?: Map<any, any>;
400-
intro?: boolean;
401-
}): Exports;
413+
}
414+
/**
415+
* Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component.
416+
* Transitions will play during the initial render unless the `intro` option is set to `false`.
417+
*
418+
* */
419+
export function mount<Props extends Record<string, any>, Exports extends Record<string, any>>(component: ComponentType<SvelteComponent<Props>> | Component<Props, Exports, any>, options: MountOptions<Props>): Exports;
402420
/**
403421
* Hydrates a component on the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component
404422
*

0 commit comments

Comments
 (0)