Skip to content

Narrow mount() return type #15925

@hyunbinseo

Description

@hyunbinseo

Describe the problem

Current mount API returns Record<string, any>

/**  * Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component.  * Transitions will play during the initial render unless the `intro` option is set to `false`.  *  * @template {Record<string, any>} Props  * @template {Record<string, any>} Exports  * @param {ComponentType<SvelteComponent<Props>> | Component<Props, Exports, any>} component  * @param {MountOptions<Props>} options  * @returns {Exports}  */ export function mount(component, options) { return _mount(component, options); }

For cases like wxt, app has to be typed like this:

let app: Record<string, any>;
import { mount, unmount } from 'svelte'; import App from '../lib/App.svelte'; export default defineContentScript({ main: async (ctx) => { let app: Record<string, any>; createShadowRootUi(ctx, { onMount: (uiContainer) => { app = mount(App, { target: uiContainer }); }, onRemove: () => unmount(app), }).then((ui) => ui.mount()); }, });

Describe the proposed solution

Provide a Mounted type.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions