Skip to content

Commit

Permalink
Don't infer types of selectors in mixins (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mad-Kat authored Nov 29, 2024
1 parent 411ad36 commit 365af90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-pants-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-yak": patch
---

Fix typings of selectors within mixin
19 changes: 19 additions & 0 deletions packages/next-yak/runtime/__tests__/typeTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,22 @@ const KeyframesWithConstants = () => {
}
`;
};

const SelectorMixinsShouldNotAlterType = () => {
const Button = styled.button<{ $primary?: boolean }>``;

const Mixin = css`
${Button} {
color: red;
}
`;

const X = styled.div`
${Button} {
color: blue;
}
${Mixin};
`;

<X />;
};
2 changes: 1 addition & 1 deletion packages/next-yak/runtime/cssLiteral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type PropsToClassNameFn = (props: unknown) =>
export function css(styles: TemplateStringsArray, ...values: []): StaticCSSProp;
export function css<TProps = {}>(
styles: TemplateStringsArray,
...values: CSSInterpolation<TProps & { theme: YakTheme }>[]
...values: CSSInterpolation<NoInfer<TProps> & { theme: YakTheme }>[]
): ComponentStyles<TProps>;
export function css<TProps>(
...args: Array<any>
Expand Down
2 changes: 1 addition & 1 deletion packages/next-yak/runtime/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const yakStyled = <
CSSInterpolation<T & NoInfer<TCSSProps> & { theme: YakTheme }>
>
) => {
const getRuntimeStyles = css(styles, ...values);
const getRuntimeStyles = css(styles, ...(values as any));
const yak = (props: Substitute<TCSSProps & T, TAttrsIn>, ref: unknown) => {
// if the css component does not require arguments
// it can be called without arguments and we skip calling useTheme()
Expand Down

0 comments on commit 365af90

Please sign in to comment.