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

Conditional properties through discriminated unions and intersections in TypeScript #7553

Closed
roydukkey opened this issue Jan 18, 2023 · 2 comments
Labels
✨ feature request New feature or request

Comments

@roydukkey
Copy link

What problem does this feature solve?

It would be very useful to explain component properties the following manner.

interface CommonProps {
    size?: 'xl' | 'l' | 'm' | 's' | 'xs';
}

type ConditionalProps = {
    color?: 'normal' | 'primary' | 'secondary';
    appearance?: 'normal' | 'outline' | 'text';
} | {
    color: 'white';
    appearance: 'outline';
};

type Props = CommonProps & ConditionalProps

What does the proposed API look like?

This issue is related to #4294, but the use case is different.

Here is an article that goes into more information on this approach.

@roydukkey roydukkey added the ✨ feature request New feature or request label Jan 18, 2023
@sxzz
Copy link
Member

sxzz commented Jan 29, 2023

Supported in Vue Macros vue-macros/vue-macros@2a6e990

@rob-pace
Copy link

rob-pace commented May 13, 2023

@sxzz Do you know how this would be accomplished using .ts?

export default defineComponent({
  name: 'MyComponent',
  props: {
    // are there vue native types that can be imported here to support discriminated unions and intersections?
  },
  setup() {
    return () => (
      // ...
    )
  }
})

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

3 participants