Skip to content

Conditional properties through discriminated unions and intersections in TypeScript #7553

Closed
@roydukkey

Description

@roydukkey

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.

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