makeStyles theme parameter typing is not accurate
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Explain what you did
const useStyles = makeStyles((theme) => ({
root: {
backgroundColor: theme.colors.white,
},
});
... error ... theme.colors could possibly be undefined
Expected behavior
The theme
param is Partial<FullTheme>
however it appears that the colors
property is always present. Param type should reflect this.
Describe the bug
Allow developers to assume full theme.colors.xxx
set of values are present and defined.
Steps To Reproduce
See code above.
Screenshots
No response
Your Environment
Used the "bleeding edge" install instructions
* react-native-elements: 4.0.0-beta.0 (sometimes also referred to as 4.0.0-beta.1 during install)
* expo: 44.0.6
* typescript: 4.6.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
material-ui typescript makeStyles() types - Stack Overflow
What type do I have to declare for the theme parameter? importing and using the Theme type still gives same error. When I...
Read more >mui/material-ui - Typescript 3.5 causes makeStyles problem
const useStyles = makeStyles((theme: Theme) => createStyles({ root: ... No hurry of course, but 3.5.1 is the latest tag on npm right now....
Read more >TypeScript - Material UI - MUI
To get the best type experience with the types we recommend setting "strict": true . Handling value and event handlers. Many components concerned...
Read more >Material-UI makeStyles, useStyles, createStyles, and ...
5 MUI makeStyles with Props, Theme, and TypeScript ... React had not yet introduced hooks back when Material-UI 3 was first released.
Read more >Material UI Tutorial #6 - Custom Themes - YouTube
Hey gang, in this material UI tutorial we'll take a look at how to create custom themes (colours, spacing, typography, etc) for your ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@arpitBhalla - I have updated to the latest (
rc2
) version of this lib and when I callmakeStyles
like below I am still getting an error sayingtheme.colors is possibly undefined
. I see you fixed the type withinFullTheme
to saycolors
is mandatory, but themakeStyles
call still hastheme: Partial<FullTheme>
. I’m not sure why that should bePartial
I can confirm that
useTheme
is returning the full theme now withcolors
being required.Yes there would be always colors property, even if you don’t use ThemeProvider