stitches icon indicating copy to clipboard operation
stitches copied to clipboard

The VariantProps generic type should return variants of an extended component

Open joseDaKing opened this issue 4 years ago • 3 comments

Is your feature request related to a problem? Please describe. The VariantProps generic type should return variants of an extended component

Describe the solution you'd like The VariantProps generic type does not return variants of an extended component

export const Box = styled("div", {
    display: "block",
    variants: {
        inline: {
            true: {
                display: "inline-block"
            }
        }
    },
    defaultVariants: {
        inline: true
    }
});

const Container = styled(Box, {
    display: "block"
});

// Is an empty object
type ContainerVariants = VariantProps<typeof Container>;

Describe alternatives you've considered We could do this instead

type ContainerVariants = VariantProps<typeof Box>;

joseDaKing avatar Oct 14 '21 20:10 joseDaKing

A knock-on effect of this is that you can't use all keys in defaultVariants for components that have been extended.
To use your example, the following would throw an error claiming inline doesn't exist:

const Container = styled(Box, {
    display: "block"
    defaultVariants: { inline: true }
});

jacobclarke92 avatar Oct 18 '21 09:10 jacobclarke92

This is a good point. Thanks for raising. We had reached some TS limitations when we built this initially. We'll have to give it another go.

peduarte avatar Oct 22 '21 07:10 peduarte

Any update?

azuline avatar Feb 16 '22 00:02 azuline