-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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 & withStyles error when has 'position' #8928
Comments
This is is due to TypeScript's type widening. It's treating const styles = {
container: {
// explicitly cast as literal type
position: 'absolute' as 'absolute',
// ...
},
} // indicate the type at the top level, causing literals to be inferred within the object
const styles: StyleRules<'container'> = {
container: {
position: 'absolute',
// ...
},
} // apply withStyles immediately to the styles object, also allowing inference to defeat type widening
const decorate = withStyles({
container: {
position: 'absolute',
// ...
},
} Personally I favor the last option. |
If #8819 is merged, you could also do const styles = {
container: style({
position: 'absolute',
...
}),
} |
@pelotom thanks for the help! The last one doesn't work for me when I use a function: const decorate = withStyles(({ palette }) => ({
container: {
position: 'absolute',
// ...
},
})); |
@adriantoine in this case TypeScript's type inference breaks down... the solution is to provide a type parameter of the class keys: const decorate = withStyles<'container'>(({ palette }) => ({
container: {
position: 'absolute',
// ...
},
})); |
Thanks for that, I would never have know this |
Compilation error, when:
export const Desktop = withStyles(styles)<Page>(DesktopComponent)
Where:
Expected Behavior
Looks like it's a default key, but I have an error.
Current Behavior
Have following compilation error:
Context
Your Environment
The text was updated successfully, but these errors were encountered: