question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

makeStyles theme parameter typing is not accurate

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mbyrne00commented, Apr 29, 2022

@arpitBhalla - I have updated to the latest (rc2) version of this lib and when I call makeStyles like below I am still getting an error saying theme.colors is possibly undefined. I see you fixed the type within FullTheme to say colors is mandatory, but the makeStyles call still has theme: Partial<FullTheme>. I’m not sure why that should be Partial

const useStyles = makeStyles((theme) => ({
   root: {
       borderColor: theme.colors.primary,
   }
});

I can confirm that useTheme is returning the full theme now with colors being required.

0reactions
arpitBhallacommented, Mar 21, 2022

Yes there would be always colors property, even if you don’t use ThemeProvider

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found