Skip to content
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

[typescript] Improve type definition for withStyles #8320

Merged
merged 12 commits into from
Sep 22, 2017
22 changes: 11 additions & 11 deletions test/typescript/styles.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ const AllTheComposition = withTheme(
// Can't use withStyles effectively as a decorator in TypeScript
// due to https://github.com/Microsoft/TypeScript/issues/4881
// @withStyles(styles)
class DecoratableComponent extends React.Component<WithStyles<StyledComponentProps, 'root'>> {
render() {
const { classes, text } = this.props;
return (
<div className={classes.root}>
{text}
</div>
);
const DecoratedComponent = withStyles(styles)(
class extends React.Component<WithStyles<StyledComponentProps, 'root'>> {
render() {
const { classes, text } = this.props;
return (
<div className={classes.root}>
{text}
</div>
);
}
}
}

const DecoratedComponent = withStyles(styles)(DecoratableComponent);
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently the least painful way in TypeScript that you can use a type-mutating decorator on a class.


// no 'classes' property required at element creation time (#8267)
<DecoratedComponent text="foo" />