Skip to content

Using Component for typing doesn't allow for any other props outside the required. #13195

@pauldemarco

Description

@pauldemarco

Describe the problem

How can I create a function that takes a Component that has at least the foo prop?

/*
* @param modal: any Component that has at least the `foo` prop
*/
function showModal(modal: Component<{foo: string; [key: string]: any}>) {
    // do some things and use `mount`
}

// gives errors if SimpleDialog has any more props than `foo`:
showModal(SimpleDialog)

Repl (doesn't show ts-errors)

REPL

I have also tried attempts at using extends for the type, to no avail.

Importance

i cannot use svelte without it

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