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
[Community help wanted] useComponentDefaultProps types with strict mode in tsconfig? #3717
Comments
The types are correct, useComponentDefaultProps returns props type of props, it has no extra logic for detecting what values are defined in defaultProps and I doubt that it is even possible. This works fine in Mantine codebase because we do not use strct mode. It is not planned to change this behavior. |
Maybe someone can help people like me who use strict: true to find a workaround without manually bindings with as const? |
I wouldn't say I'm an expert but I'm an advocate for strict mode and therefore confronted with various issues. :D I've tried to reconstruct your example locally. For me in Mantine v5 even using So I will skip v5 and just provide an alternative for TypeScript 4.9 introduced the
The result is comparable to Is this good enough for your? For me this would be clean enough because it clearly describes the relation between the props and default props. |
@cyantree thank you, man! It works! I have props suggestion and no errors! |
I apologize for the inconvenience my PR caused you. What I had in mind was that |
The one problem now (actually for users that uses next.js with babel config): babel configs in next.js not supports satisfies operator now, because babel have unresolved issue and this occurs in next.js projects with babel config. |
I think if it should be solved without relying on these things
I've also discovered that currently it's technically possible to pass some additional props in Is there a reason why currently the return type isn't something like However But TBH I have a hard time understanding these mapped times with utility types and modifiers, so I haven't fully grasped the current return type yet. Maybe I'll deepdive in the original PR #2065. |
I have tried the issue with type checking, but I'm not sure why this phenomenon is different from what I demonstrated in the demo code. I hope this demo will be helpful for you. |
I'm sorry but I think I lost the thread. So to recap: So to get around this there are currently three possibilities:
So IMHO the original problem has been solved, correct @7iomka ? Afterwards we discussed the correctness of the return type as I think it has some flaws. But here I'm not sure if it's useful to tackle that:
So if the original problem is resolved I think this issue can be closed. What do you all think? |
I will close this, but maybe needed to make a notice about this in the documentation |
What package has an issue
@mantine/core
Describe the bug
Hi.
I plan to migrate to v6 in a near future, but this issue occurred earlier and is still actual in version 6 as well (I attached demo for both versions).
In the example I created a custom component according to the documentation
How you see, we have an type issue, my component receive optional props which can be used in useStyles hook, but, because of nature of createStyles, some of this props are required, so for that case I declared it in defaultProps, but final type is still have error, because type of defaultProps is an Partial from component props.
The one possible workaround for this is to use
as const
binding without typeI saw this workaround you use in your code, but it is not reflected in the documentation in any way. Moreover, in other parts of your code you don't seem to encounter this problem, and I assume it has something to do with the way the types are exported to the end-user module.
I would appreciate your comments on this.
What version of @mantine/hooks page do you have in package.json?
5.10.5
If possible, please include a link to a codesandbox with the reproduced problem
V5 - https://codesandbox.io/s/sweet-nova-1hdww2?file=/src/components/shipment-item/shipment-item.component.tsx:1651-1695
V6 - https://codesandbox.io/s/zen-currying-zj0zbb?file=/src/components/shipment-item/shipment-item.component.tsx:1651-1695
The text was updated successfully, but these errors were encountered: