V6: What is the proper type for Interpolations / RuleSets? #3915
-
|
What is the proper way to add types for the return value of We're wondering if there is a preferred way to handle this type. Consider the following code using Typescript and // util.ts
import type { FlattenSimpleInterpolation } from `styled-components;
export const withReducedMotion = (styles: FlattenSimpleInterpolation) => `
@media (prefers-reduced-motion) {
${ styles }
}
`// Component.ts
const dialogAnimation = css`
//...
${withReducedMotion(css`
animation-duration: 0;
`)}
`For now we have been using // util.ts
import type { css } from `styled-components;
export const withReducedMotion = (styles: ReturnType<typeof css>) => `
@media (prefers-reduced-motion) {
${ styles }
}
` |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
styled-components v6 RC ( |
Beta Was this translation helpful? Give feedback.
-
|
In v6, use the import type { RuleSet } from 'styled-components';
import { css } from 'styled-components';
const myStyles: RuleSet = css`
color: red;
`;
|
Beta Was this translation helpful? Give feedback.
In v6, use the
RuleSettype exported from styled-components:FlattenSimpleInterpolationwas removed in v6.RuleSetis the canonical replacement.