Skip to content
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

useSafeSetState incompatible with @types/react@16.14 and later #5949

Closed
bayareacoder opened this issue Feb 23, 2021 · 1 comment · Fixed by #5950
Closed

useSafeSetState incompatible with @types/react@16.14 and later #5949

bayareacoder opened this issue Feb 23, 2021 · 1 comment · Fixed by #5950
Assignees
Labels

Comments

@bayareacoder
Copy link

bayareacoder commented Feb 23, 2021

What you were expecting:
react-admin should compile in Typescript when using @types/react@16.14 or @types/react@17

What happened instead:
Throws an error at compile time due to the return type from the returned destructor from useSafeSetState in file ra_core/src/util/hooks.ts

   const mountedRef = useRef(false);
  > 12 |     useEffect(() => {
       |               ^
    13 |         mountedRef.current = true;
    14 |         return () => (mountedRef.current = false);
    15 |     }, []);

Type 'boolean' is not assignable to type 'void | { [UNDEFINED_VOID_ONLY]: never; }'

Root cause:
Type definitions for EffectCallback changed to explicitly disallow to return anything else than void from the Destructor

From @types/react@16.9

  type EffectCallback = () => (void | (() => void | undefined));

To @types/react@16.14 (maybe already from earlier version but not tested)

type EffectCallback = () => (void | Destructor);
type Destructor = () => void | { [UNDEFINED_VOID_ONLY]: never };
declare const UNDEFINED_VOID_ONLY: unique symbol;

Fix
2 character fix: replace () by {}

Environment

  • React-admin version: 3.12.5
@fzaninotto
Copy link
Member

Thanks for the detailed description and root cause analysis. The fix is simple indeed.

WiXSL pushed a commit to WiXSL/react-admin that referenced this issue Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants