jantimon / next-yak

a streamlined CSS-in-JS solution tailor-made for Next.js, seamlessly combining the expressive power of styled-components syntax with efficient build-time extraction and minimal runtime footprint, ensuring optimal performance and easy integration with existing atomic CSS frameworks like Tailwind CSS
https://yak.js.org
108 stars 2 forks source link

Fix composition types #104

Closed Mad-Kat closed 2 months ago

Mad-Kat commented 2 months ago

Fixes #72

Use NoInfer<T> in order to be explicit for the tagged template literal types and not inferring them from the functions that are used for dynamic props or child components.

Added bonus: The destructuring of the props in the tagged template literal gives you now type hints, as TypeScript doesn't want to infer it dynamically and the type is known when you start with the literal.

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-yak-benchmark ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 11:17am
yacijs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 11:17am
codspeed-hq[bot] commented 2 months ago

CodSpeed Performance Report

Merging #104 will not alter performance

Comparing fix-composition-types (ef119e8) with main (7b0de33)

Summary

✅ 2 untouched benchmarks

jantimon commented 2 months ago

Just checked and styled-component seems to behave the same: https://stackblitz.com/edit/vitejs-vite-vttcyb?file=src%2Fmain.tsx,src%2FApp.tsx&terminal=dev

I adjusted the tests and added @ts-expect-error

Mad-Kat commented 2 months ago

Yeah I think you need to write it like this:

const Parent = styled.div<{ $colorMe: boolean }>`
      ${Child} {
        color: blue;
      }
      color: ${({ $colorMe }) => $colorMe ? `blue` : `red`};
    `;

you have to add the type parameter in order to say that $colorMe exists. It doesn't automatically infer it from the functions you provide.

jantimon commented 2 months ago

released as 0.2.2