[bug?] withStyles not working as a regular function in TypeScript.
See original GitHub issueEDIT: I was trying to use it as a decorator, which the docs say isn’t supported, but even as a function I get the same error (below)
Seems like this was supposed to be fixed back in https://github.com/mui-org/material-ui/pull/8178, but I’m on @material-ui/core
3.9.0 and typescript 3.1.6 and it isn’t working.
F.e.
@withStyles(baseStyles)
export default class LayerManager extends React.Component<{...}, {...}> {
gives the error
error TS2345: Argument of type 'typeof LayerManager' is not assignable to parameter of type 'ComponentType<never>'.
[1] Type 'typeof LayerManager' is not assignable to type 'ComponentClass<never, any>'.
[1] Type 'LayerManager' is not assignable to type 'Component<never, any, any>'.
[1] Types of property 'props' are incompatible.
[1] Type 'Readonly<{ children?: ReactNode; }> & Readonly<ILayerManagerProperties>' is not assignable to type 'never'.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
[bug?] withStyles not working as a regular function in TypeScript.
EDIT: I was trying to use it as a decorator, which the docs say isn't supported, but even as a function I get...
Read more >Material-ui-next withStyles decorator doesn't work correctly
I'm rewriting my little project to material-ui, and I'm using for this material-ui-next reactjs library; For one component withStyle ...
Read more >Typing React with typescript - DEV Community
Since we use MUI we handle styling with JSS and the generated CSS classes are injected via the withStyles HOC. This caused some...
Read more >Documentation - Do's and Don'ts - TypeScript
❌ Don't ever use the types Number , String , Boolean , Symbol , or Object These types refer to non-primitive boxed objects...
Read more >Using styled-components in TypeScript: A tutorial with examples
Here, you can learn how to build and style a TypeScript app using styled-components, with an e-commerce page as an example.
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 Free
Top 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
I found another way to fix it. I can also replace
with
Notice the only difference is the question mark
?
.The error that we’re getting leaves us with no clue as to what’s happening. Is there some way to make the error more helpful, so that it may tell us that we’ve extended the constructor improperly?
@trusktr
context
needs to be optional in the constructor. This is implied in the react typings.not assignable to never
usually indicates that you passed the wrong type.