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

Fixed typings for makeStyles return function #13801

Closed
wants to merge 1 commit into from
Closed

Fixed typings for makeStyles return function #13801

wants to merge 1 commit into from

Conversation

bartekczyz
Copy link

Return function accepts optional props argument. Fixed TS typings. See https://github.com/mui-org/material-ui/blob/master/packages/material-ui-styles/src/makeStyles.js#L30

Return function accepts optional `props` argument. Fixed TS typings
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like add a typings test for that. Isn't it possible now to call it without props when the actual styling function accesses those props? That would possibly throw at runtime, no?

@bartekczyz
Copy link
Author

Sorry mate, I have totally no idea what are you asking, could you please elaborate more on that?

@eps1lon
Copy link
Member

eps1lon commented Dec 4, 2018

Sorry mate, I have totally no idea what are you asking, could you please elaborate more on that?

This throws at runtime:

const useStyles = makeStyles({ root: props => ({ color: props.nested.value }) });

function Component(props) {
  const classes = useStyles(); // cannot read property value of undefined
  return <div className={classes.root}>Hello, World!</div>
}

<Component nested={{ value: 'green' }} />

but would be accepted at compile time now.

There is a little bit more work involved. I think you should start with Styles and then work up. Start by writing code that should be valid at compile time (i.e. in a TS file) and code that should error at compile time. Then change the declarations accordingly.

@eps1lon eps1lon added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Dec 4, 2018
@bartekczyz bartekczyz closed this Dec 5, 2018
@bartekczyz bartekczyz deleted the patch-1 branch December 5, 2018 10:29
@eps1lon
Copy link
Member

eps1lon commented Dec 5, 2018

@bartekczyz See #13815 for my solution. 734018b includes tests (the $ExpectError are responsible for that) and ca668d5 the fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants