Type errors when interpolating into tagged template literal #188
Labels
package: system
Specific to @mui/system
status: waiting for maintainer
These issues haven't been looked at yet by a maintainer
Milestone
Steps to reproduce
Hello, first of all, thank you for this great project!
Context: We have a larger Next.js app with many Styled Components. We're currently figuring out if and how certain Styled Components syntax features can be represented in Pigment.
I'm currently testing what can be interpolated when using the tagged template syntax styled.tag`…`, specifically interpolating a string, a function and an object.
(I know that Pigment favors the object notation for these cases and I agree this is a more flexible and powerful syntax. I understand that you need to focus your energies on the recommended syntax. Coming from a Styled Components code base though, I'd like to assess to what extent Pigment supports the tagged template syntax. I'm not sticking to any particular syntax in the long term, just want to find out what works with minimal changes and what requires an architectural change.)
Let's say I have these reusable styles:
When I interpolate the object into a component and also pass a function to access a theme token:
This works as expected (all styles are applied) and there is no TS error on the declaration. At the place of usage with children though:
TypeScript 5.3.3 (NOT the latest TypeScript 5.5.4) raises an error:
Testing further, direct string interpolation does not work (is this not implemented yet or a deliberate decision?). But it seems I can pass a function that returns a string:
This works fine again (all styles applied) and raises no TS errors.
When I mix functions that return an object + string though:
This works (all styles are applied) but raises a TypeScript error:
It seems Pigment does support the cases above (except for the direct ${string} interpolation). So only the types are a bit off, or am I mistaken?
Here's a minimal Next 14 app with latest Pigment:
https://github.com/molily/next14-pigment
Here's the file with the test code:
https://github.com/molily/next14-pigment/blob/main/src/app/PigmentOverview.tsx
Current behavior
Interpolation of different objects/functions into tagged template literal may cause a TypeScript error. One error disappears in the newest TypeScript version, the other remains.
Expected behavior
It should be clear which arguments can be passed to the tagged template literal, and types should reflect these capabilities.
Context
Next app with Styled Components adopting Pigment CSS
Your environment
Node v20.14.0
next 14.2.5
@pigment-css/nextjs-plugin 0.0.18
@pigment-css/react 0.0.18
typescript 5.3.3
Search keywords: tagged template literal, functions, TypeScript, Styled components migration
The text was updated successfully, but these errors were encountered: