Closed NicklasWallgren closed 2 years ago
Record<string, CSSObject>
solved it.
Hi,
You just need to add as const
-position: "relative"
+position: "relative" as const
If you don't, TypeScript see the value of position as a string
and it's not happy because he is expecting "relative" | "absolute" | ...
@garronej Thanks for the explanation.
I solved the issue by defining the return type Record<string, CSSObject>
. But as const
would probably have worked as well.
export const tableFilterStyles = (theme: Theme): Record<string, CSSObject> =>
({
root: {
position: "relative"
},
....
});
Hey,
I'm currently migrating from MUI 4 to version 5 and have encountered some weird behaviour.
I've got a two files
tableFilterStyles.ts
andTableFilter.tsx
containingtableFilterStyles.ts
TableFilter.tsx
For some particular reason Typescript doesn't like the
position.relative
object. "Type 'string' is not assignable to type '"relative" Everything else works expect "position".I guess I need to add a return type to the
tableFilterStyles
function, maybecssObjectByRuleNameOrGetCssObjectByRuleName
?Do you have any idea?
If I pass the style directly it works
Thanks!
The whole error message;