Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jd-solanki opened this issue Apr 27, 2023 · 2 comments
Labels
✨ feature request New feature or request

Comments

@jd-solanki
Copy link

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>

@jd-solanki jd-solanki added the ✨ feature request New feature or request label Apr 27, 2023
@modelair
Copy link

modelair commented Apr 27, 2023

did u mean this?

 interface MyProps extends MyOtherProps {
  color?: MyColor
  modelValue?: number
} 

const props = withDefaults(defineProps<MyProps>(), {
  color: 'green',
  modelValue: 0
})

@jd-solanki
Copy link
Author

Thanks for your response.

No! It's already in docs.

I'm saying, Generating type from object syntax as shared in the code snippet.

@jd-solanki jd-solanki changed the title Utility type to generate type/interface from props object syntax ExtractExternalPropTypes - Utility type to generate type/interface from props object syntax Apr 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants