WithStyles<typeof styles> not working properly
See original GitHub issueWithStyles<typeof styles>
doesn’t get along with with TS (no auto completion and I get type mismatch error).
- This is a v1.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
New Material UI Core’s WithStyles<>
should be able to receive the the type of styles
object somehow, for further auto-completion of classes from this.props.classes
.
It works only if I hardcode the class names (i.e. WithStyles<'className'>
), but it contradicts DRY principle.
Current Behavior
I tried WithStyles<typeof styles>
, WithStyles<keyof typeof styles>
, but nothing works.
I don’t get auto-completion for the classes and also type checking fails using withStyles
:
const styles = (theme: Theme) => createStyles({
someClass:
});
interface Props extends WithStyles<typeof styles> {
prop: string
}
class SomeClass extends React.Component<Props> {... }
export default withStyles(styles)<Props>(SomeClass);
Tried also without createStyles
or just withStyles(styles)(SomeClass)
, but nothing works.
Using WithStyles<keyof typeof styles>
, I get no classes auto-completion, but types match.
Using WithStyles<typeof styles>
, no auto completion and type mismatch error in withStyles
:
...
Type SomeClass no match for signature
'(props: Props & Partial<WithTheme> & { classes: Record<string, string>;
string? any; T: string; StyleRulesCallback<infer, K>(): any ...}'
Steps to Reproduce
Written above.
Context
I can proceed with development by hardcoding all classnames or giving up on type checking, but it’s frustrating.
Your Environment
Tech | Version |
---|---|
Material-UI | v1.2.0 |
React | v16.4.0 |
Typescript | v2.9.2 |
Issue Analytics
- State:
- Created 5 years ago
- Comments:18 (16 by maintainers)
Top GitHub Comments
@franklixuefei I see, makes sense. Good luck with the PR!
WithStyles<keyof ReturnType<typeof styles>>