-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better developer experience with withStyles & typescript #12070
Comments
@oliviertassinari i hope to start discussion about it :) |
@Bnaya Thanks for sharing your work! But I'm not really involved in the TypeScript story. Could you check that out with Tom? :) |
Hey @pelotom, dose it look like something you would want to include as part of the library? |
@Bnaya could you summarize the main innovation here? It seems like some of what you're proposing is already handled fine by the core typings. For example you can just write this const stylesDeclerations = (theme: Theme) => createStyles({
body: {
textAlign: "center",
},
headline: {
textAlign: "left",
},
});
const stylesInjector = withStyles(stylesDeclerations);
interface IProps extends WithStyles<typeof stylesDeclerations> {
title: string;
caption: number;
} and the only difference is that |
OK, |
We could definitely use types which accurately model when the |
@pelotom please take a look at |
I think a better solution will be: // types
type ClassesType<S extends (...args: any[]) => any, T extends ReturnType<S>> = {
[P in keyof T]: string
};
interface WithStyles<T extends (...args: any[]) => any> {
classes: ClassesType<T, ReturnType<T>>;
}
// example of use
const styles = (theme: Theme) =>
createStyles({
root: {
display: "flex",
flexDirection: "column",
flex: 1
},
center: {
alignItems: "center"
}
});
export interface IProps extends WithStyles<typeof styles> {
otherProp: boolean;
}
const Component = ({ otherProp, classes, ...props }: IProps) => {
...
// here classes.root & classes.center will be only options
} this will automatically add all the styles as string. What do you guys think ? |
@ghalex I think the original issue is resolved. So if you have any more issues with the latest version please open a separate issue. Have you checked out https://material-ui.com/guides/typescript/? |
I would like to share with you our latest iteration of improved withStyles and typescript.
We think it's really awesome.
I believe that after we find a good naming for the methods we can make a PR :)
There's hardcoded
{ withTheme: true }
. but i will change that if there will be a need to something with type overloading or soThe text was updated successfully, but these errors were encountered: