diff --git a/src/styles/withStyles.d.ts b/src/styles/withStyles.d.ts index d8f4ca5ea274d9..31eeeaf8780400 100644 --- a/src/styles/withStyles.d.ts +++ b/src/styles/withStyles.d.ts @@ -24,7 +24,7 @@ declare function withStyles( style: StyleRules | StyleRulesCallback, options?: WithStylesOptions ): < - C extends React.ComponentType

, + C extends React.ComponentType

, P = {}, ClassNames = {} >( @@ -35,7 +35,7 @@ declare function withStyles

( style: StyleRules | StyleRulesCallback, options?: WithStylesOptions ): ( - component: React.ComponentType

+ component: React.ComponentType

) => React.ComponentClass

> export default withStyles; diff --git a/test/typescript/styles.spec.tsx b/test/typescript/styles.spec.tsx index cda6c826c94fc9..3f21a4ad0c1fb9 100644 --- a/test/typescript/styles.spec.tsx +++ b/test/typescript/styles.spec.tsx @@ -124,3 +124,40 @@ class DecoratedComponent extends React.Component< ); } } + +// Avoid naming conflict with 'StyledComponentProps' used in other tests +import { StyledComponentProps as MUIStyledComponentProps } from '../../src'; +// Ensure that providing a classes prop is optional for components that use withStyles +const WithStylesDoesntRequireClassesTest = () => { + + const styles = theme => ({ + root: { + color: "aqua" + } + }); + + interface NoClassesRequiredStyles { + root: string + } + + type NoClassesRequiredProps = { + bestComponentLibrary: string + } & MUIStyledComponentProps + + /* If classes regresses and is no longer nullable for components using + withStyles, this will not compile. */ + @withStyles(styles) + class NoClassesRequired extends React.Component { + + render() { + const classes = this.props.classes; + return ( +

+ ); + } + + } + + + +};