Open Jack-Works opened 1 year ago
We temporally cast makeStyles
as the following type, it works well.
{
makeStyles: <Params = void, RuleNameSubsetReferencableInNestedSelectors extends string = never>(params?: {
name?: string | Record<string, unknown>
uniqId?: string
}) => <RuleName extends string>(
cssObjectByRuleNameOrGetCssObjectByRuleName:
| Record<RuleName, CSSObject>
| ((
theme: Theme,
params: Params,
classes: Record<RuleNameSubsetReferencableInNestedSelectors, string>,
) => Record<RuleNameSubsetReferencableInNestedSelectors | RuleName, CSSObject>),
) => <StyleOverrides extends { classes?: { [key in string]?: string | undefined } }>(
params: Params,
styleOverrides?: {
props: StyleOverrides
ownerState?: Record<string, unknown>
},
) => {
classes: StyleOverrides extends { classes?: { [key in infer ExtraKeys]?: string | undefined } }
? Record<ExtraKeys | RuleName, string>
: Record<RuleName, string>
theme: Theme
css: Css
cx: Cx
}
}
Hey @Jack-Works,
Thank you for the feedback! I understand your usecase, it makes sences.
What I do currently if I something like this but I get this is not optimal.
import { useMergedClasses } from "tss-react";
type Props = {
//classes?: { foo?: string; bar?: string; };
classes?: Omit<Partial<ReturnType<typeof useStyles>["classes"]>, "onlyInternal">;
};
function MyTestComponentForMergedClassesInternal(props: Props) {
const { classes } = useStyles({ "color": "pink" }, { props });
//NOTE: Only the classes will be read from props,
//you could write { props: { classes: props.classes } } instead of { props }
//and it would work the same.
return (
<div className={classes.foo}>
<span className={classes.somethingForOverwriting}>
</span>
<span className={classes.onlyIntenal}>
</span>
</div>
);
}
const useStyles = makeStyles<{ color: string; }>()({
"foo": {
"border": "3px dotted black",
"backgroundColor": "red"
}
"somethingForOverwriting": {},
"onlyInternal": {
"color": "red"
}
});
I'll think about it. Glad you found a workaround for now.
Best regards
We're upgrading from v3 to v4 and are happy to find the new feature, but we found some problem with TypeScript.
In our old implementation, we call it
useStyleExtends
and it is implemented in the follow way:This implementation allows us to extend the type of classes in the props. This is our pattern of customizable components.
After migrating to tss-react v4 new API, we found the new API is not sufficient to replace our old one: