Struggling with implementing the media templates example from the documentation and figuring out how to type the arguments for the css function in plain JS:
const sizes = {
desktop: 992
}
const media = Object.keys(sizes).reduce((acc, label) => {
acc[label] = (...args) => css` // <----- need help typing args
@media(max-width: ${sizes[label]}px) {
${css(...args)}
}
`
return acc
}, {})
If you are familiar with TypeScript but not styled-components, args is a tagged template literal used as below:
media.desktop`
background-color: blue;
${variable}
`
Attempted typing args as TemplateStringsArray but confronted with complaints from TS regarding spread argument types. Changing the type to TemplateStringsArray[] causes issues with the css() function expecting at least one argument but receiving 0 or more.