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] Restore withStyles class decorator #8354

Merged
merged 3 commits into from
Sep 24, 2017

Conversation

pelotom
Copy link
Member

@pelotom pelotom commented Sep 24, 2017

This is a follow-on to #8320 which reenables using withStyles as a class decorator in TypeScript, while preserving the fix for #8267:

@withStyles(styles)
class DecoratedComponent extends StyledComponent<NonStyleProps, 'root'> {
  render() {
    return (
      <div className={this.props.classes!.root}> // <-- `!` required if `strictTypeChecks` is enabled
        {this.props.text}
      </div>
    );
  }
}

The only caveat is that with strictNullChecks enabled, one needs to use the non-null assertion operator (!) on accesses of classes.

@oliviertassinari oliviertassinari merged commit 94837a3 into mui:v1-beta Sep 24, 2017
@oliviertassinari
Copy link
Member

@pelotom I'm having a hard time understanding the TypeScript typing system. I need to ship a release, so I'm simply going to merge given the tests are green :).
Thanks

@pelotom pelotom deleted the ts-restore-withStyles-decorator branch September 24, 2017 18:59
@pelotom
Copy link
Member Author

pelotom commented Sep 24, 2017

@oliviertassinari I opened a PR to document the new typings: #8364. Hopefully that clarifies it somewhat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants