atlassian-labs / compiled

A familiar and performant compile time CSS-in-JS library for React.
https://compiledcssinjs.com
Apache License 2.0
1.98k stars 68 forks source link

Passing a `css` output as a value to another `css` call fails with no type error (etc) #1647

Open kylorhall-atlassian opened 5 months ago

kylorhall-atlassian commented 5 months ago

Describe the bug

The pattern of passing a css output to a value in another css does not work in Compiled, but it also does not fail type-checking. There only way to determine this doesn't work is by trying it. This could be problematic in migration from another CSS-in-JS library primarily.

const styles1 = css({ color: 'red' });
const styles2 = css({ '&:hover': styles1 });

I did not test this with styled.div({ '&:hover': styles1 });, but I expect it might not work as well. It does not throw a type error.

To Reproduce

[tested in a local Storybook, I have no codesandbox or anything, sorry]

Expected behavior

This works in Emotion and almost certainly in the tagged template expression interpolations in Compiled, but I'd vote that we don't want to support it in Compiled, and instead should just have a type error.