From 500bd6f8e78a1079fea3683a87fa6268da5b6a1b Mon Sep 17 00:00:00 2001 From: David Blass Date: Thu, 21 Sep 2017 07:36:41 -0400 Subject: [PATCH 1/3] Allowing the classes property to be nullable when in withStyles as it is elsewhere. --- src/styles/withStyles.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From 0dbc51959c70d33361f462957aa3538307007232 Mon Sep 17 00:00:00 2001 From: David Blass Date: Thu, 21 Sep 2017 21:51:14 -0400 Subject: [PATCH 2/3] Adding a test to verify providing a classes prop is optional for components that use withStyles. --- test/typescript/styles.spec.tsx | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/typescript/styles.spec.tsx b/test/typescript/styles.spec.tsx index cda6c826c94fc9..04042b7a02b9d3 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 + + class NoClassesRequired extends React.Component { + + render() { + const classes = this.props.classes; + return ( +

+ ); + } + + } + + + + /* If classes regresses and is no longer nullable for components using + withStyles, this will not compile. */ + return withStyles(styles)(NoClassesRequired); +}; From 871657c44a96d2cd68d4ee92ce9156ec7282e474 Mon Sep 17 00:00:00 2001 From: David Blass Date: Thu, 21 Sep 2017 22:03:58 -0400 Subject: [PATCH 3/3] Updating WithStylesDoesntRequireClassesTest to instantiate the styled element. --- test/typescript/styles.spec.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/typescript/styles.spec.tsx b/test/typescript/styles.spec.tsx index 04042b7a02b9d3..3f21a4ad0c1fb9 100644 --- a/test/typescript/styles.spec.tsx +++ b/test/typescript/styles.spec.tsx @@ -144,6 +144,9 @@ const WithStylesDoesntRequireClassesTest = () => { 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() { @@ -157,7 +160,4 @@ const WithStylesDoesntRequireClassesTest = () => { - /* If classes regresses and is no longer nullable for components using - withStyles, this will not compile. */ - return withStyles(styles)(NoClassesRequired); };