-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Fix withStyles edge cases, require TS 2.8 #11280
Conversation
I took it around the block with all of my own code. All looks good! You might want to document Overwrite a bit; it takes some staring at it and examples to understand. Something like:
|
It seems like the stakeholders from the issues that this resolves are all in favor of it, so I'll merge. We'll want to mention in the release notes that TypeScript 2.8 is required now. |
@pelotom Oops, just after the release train 🚂. |
The next one will be this weekend :) |
@pelotom will this fix all the compile errors introduced around withStyle after beta.43? My code had a comfortable life before 43 :) |
@semiadam with any luck 🙂 |
@semiadam you can import the following fix instead of import withStylesOld from 'material-ui/styles/withStyles';
export * from 'material-ui/styles';
import { WithStyles, StyleRules, StyleRulesCallback, StyledComponentProps } from 'material-ui/styles';
import { WithStylesOptions } from 'material-ui/styles/withStyles';
type ConsistentWith<O> = Partial<O> & Record<string, any>;
declare function WithStylesFixed<ClassKey extends string>(
style: StyleRules<ClassKey> | StyleRulesCallback<ClassKey>,
options?: WithStylesOptions,
): {
<P extends ConsistentWith<StyledComponentProps<ClassKey>>>
(component: React.ComponentType<P & WithStyles<ClassKey>>): React.ComponentType<P & StyledComponentProps<ClassKey>>;
(component: React.ComponentType<WithStyles<ClassKey>>): React.ComponentType<StyledComponentProps<ClassKey>>;
};
export const withStyles = withStylesOld as typeof WithStylesFixed; |
@pelotom In your copious spare time, you might want to consider adding test cases for the issues that were posted due to my PR, either in this PR or another. |
I did, in this PR... were there others that I missed? |
@pelotom Sorry, no need for more AFAIK. I looked for them in the diffs, don't understand how I missed them! |
Fixes #11109.
Fixes #11191.
This employs conditional types to define an
Overwrite
type operator which resolves the edge cases aroundwithStyles
, without destroying the integrity of props that are specified as a union. This means requiring a minimum TypeScript version of 2.8.