-
-
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 Typings - Add new props type for withStyles #7830
Comments
I forgot to ping @sebald in the previous post so here it is. :) If there are other ways to get the benefits of a fully typed this.props reference then I'm open to anything. I'm relatively new to "tsx". Using type intersecting is the only way I've found to get all the available fields on props. I'm also learning that a lot of HOCs aren't really suited to be used as decorators. Are there other approaches has anyone else has taken to get fully typed |
Could you elaborate what you mean by What do you think about this? Would this be enough? const withStyles: <P = {}, ClassNames = {}>(
style: StyleRules | StyleRulesCallback,
options?: WithStylesOptions
) => (
component: React.ComponentType<P & { classes: ClassNames }>
- ) => React.ComponentClass<P>;
+ ) => React.ComponentClass<P & { classes: ClassNames, theme: Theme }>; |
I need to combine all the types related to various HOCs in order to get a fully typed props instance. In the example below I'm using
At the very least what I was requesting was an interface called In order to accomplish this I would expect the change to look like:
My final comment was just about a naming convention for the interfaces expose for them. I didn't know how attached you were to the term "Enhancement" versus something like "Props". Then we would have Does that make sense? |
I'm just playing with basic drawer stuff right now like this.
Are you using the latest type definition? You might be getting the same errors I was yesterday when I tried to use them and it broke everything for me. I can't get them to work for me at all now. I'm also still trying to decide whether it's correct to use these HOCs as decorators or not. Using it like above is "working" for me if I don't use the type definition. Sorry I can't be more hopeful. My plan right now is to wait and see if the typings issues from here get fixed and address my problems. Then I'll be back to investigating this type stuff again. #7853 (comment) |
The only preference I have when it comes to the typings is not starting every type with an "I" 😁 If people find the word "Enhancement" weird and have problems understanding them, it should be changed. At my company, we use this term whenever something is enhanced by a HOC, this originate from I personally was super hyped @ decorators (no pun intended). But stopped using them after leaving Angualr for React. Reasons are (a) they don't fit the functional style, we try to implement at my company, (b) make testing harder, if you declare your "bare bone" component and export it and then have an additional export SomeComponent:React.SFC<AllProps & WithWidthEnhancement> () => { /* ... */ }
export enhance = compose<AllProps & WithWidthEnhancement, AllAppProps>(
withWidth,
withStyles(styles, { withTheme: true })
);
export default enhance(SomeComponent); Hope this make sense. |
On other note: As soon as #7853 is resolved, I'll update the typings. |
- add `theme` - enhanced components has "styled props" Closes #7830
…nButton (#7897) * [typescript] Correct withWidth * [typescript] Rename WithWidthEnhancement. * [typescript] Improve typings for `withStyle` - add `theme` - enhanced components has "styled props" * [typescript] Correct BottomNavigationButton typings value -> any Closes #7826 Closes #7830 Closes #7889
…nButton (mui#7897) * [typescript] Correct withWidth * [typescript] Rename WithWidthEnhancement. * [typescript] Improve typings for `withStyle` - add `theme` - enhanced components has "styled props" * [typescript] Correct BottomNavigationButton typings value -> any Closes mui#7826 Closes mui#7830 Closes mui#7889
Suggestion
Currently the typings for withStyles looks like this
May I request a type be created and exported to represent the prop values that will be added when withStyles is used? Something similar to WithWidthEnhancement would be useful. It would allow people to compose it with their own custom component prop types.
Example Usage
I think this new type not only needs
classes: ClassNames
but also atheme
field now that you can toggle that to be included through the options.Another thing to consider might be to name these interfaces WithWidthProps and WithStylesProps instead.
The text was updated successfully, but these errors were encountered: