styled-components / xstyled

A utility-first CSS-in-JS framework built for React. 💅👩‍🎤⚡️
https://xstyled.dev
MIT License
2.27k stars 107 forks source link

impr(typing): infer automatically the typing of the generators used inside of the compose #358

Closed kamalbennani closed 2 years ago

kamalbennani commented 2 years ago

Summary

As the title states, the goal of this MR is to infer automatically the return type of the compose method and also support the existing type in order not to create a breaking change in that area.

Before, in order to have the correct return type, you'd have to explicitly provide the "computed" return type:

interface GridItemProps extends GridAreaProps, GridColumnProps, GridRowProps {}
const gridItem = compose<GridItemProps>(gridArea, gridColumn, gridRow);

With this new change, you'd still be able to do that (like we do internally on xstyled) or you could just write the following:

const gridItem = compose(gridArea, gridColumn, gridRow);
// generated return type
// StyleGenerator<GridAreaProps<Theme> & GridColumnProps<Theme> & GridRowProps<Theme>>
kamalbennani commented 2 years ago

Hi @gregberge, would you kindly consider my contribution? thanks.