Skip to content

ExtractExternalPropTypes - Utility type to generate type/interface from props object syntax #8168

Closed
@jd-solanki

Description

@jd-solanki

What problem does this feature solve?

Hi 👋🏻

I heavily use object syntax for defining props in my UI lib. It allows me to define prop defaults and helps me reuse the props in another component.

Assume I have props like:

const props = {
  isActive: Boolean,
}

how do I generate the type of it?

{
  isActive?: boolean
}

This is just a simple example, We can also have prop defaults and we need to set it as optional for that type/interface property.

I stumbled upon ExtractPropTypes but after exploring vue repo I found that this is not for this use case, it's for the child component.

What does the proposed API look like?

As Evan stated: export type Props = ExtractExternalPropTypes<typeof props>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions