-
Notifications
You must be signed in to change notification settings - Fork 46.5k
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
Bug: typescript can't determine well useMemo value #28185
Comments
This is a TypeScript limitation I believe. TS would also not refine the type if you put the condition in an function call which is was useMemo basically is. |
Should be fixed on TypeScript version 5.4 Preserved Narrowing in Closures Following Last Assignments |
are you still experiencing the same issues? |
The error occurs because TypeScript indicates that the organization variable can be of type Organization or undefined. This is inferred from its usage within the useMemo hook, where it is listed as a dependency along with ehrUser. When you try to pass organization directly as part of the user object, TypeScript raises an error because organization might be undefined, and therefore cannot be directly assigned to a variable of type Organization. To resolve this error, you need to check if organization is defined before attempting to use it. You can modify your code to conditionally render the UserManagement component only if organization is defined. For example: if (shouldNotRender || !organization) return null; return ( |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Thanks for posting and thanks everyone for suggestions on how to resolve. Since this isn’t an issue with React I’m going to close. |
React version:
18.2.0
TypeScript version:
5.0.2
The expected behavior
Error
The current behavior
No error
The text was updated successfully, but these errors were encountered: