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

[TypeScript] Fix types of Field components #9903

Merged
merged 2 commits into from
Jun 6, 2024
Merged

Conversation

slax57
Copy link
Contributor

@slax57 slax57 commented Jun 5, 2024

This PR fixes the following issues

  1. <ReferenceOneField> throws a TS error if the source prop is absent (although it is not mandatory)
  2. <ReferenceOneField> throws a TS error if the queryOptions prop does not contain a queryKey (although it should not be overridable)
  3. Field components memoized with genericMemo do not have the correct type, and hence will throw a TS error when passing props (such as source) to them
  4. Some stories and test files contained TS errors

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@slax57 slax57 added the RFR Ready For Review label Jun 5, 2024
@fzaninotto
Copy link
Member

Alternative: rewrite genericMemo as:

export const genericMemo = <T>(component: T): T => {
    const result = memo(component as FunctionComponent);

    // We have to set the displayName on both the field implementation and the memoized version.
    // On the implementation so that the memoized version can pick them up and users may reference the defaultProps in their components.
    // On the memoized version so that components that inspect their children props may read them.
    // @ts-ignore
    result.displayName = component.displayName?.replace('Impl', '');
    return result as unknown as T;
};

@slax57
Copy link
Contributor Author

slax57 commented Jun 5, 2024

@fzaninotto Fixed

@adguernier adguernier self-requested a review June 6, 2024 09:36
@fzaninotto fzaninotto merged commit 0f8817f into next Jun 6, 2024
14 checks passed
@fzaninotto fzaninotto deleted the fix-fields-type branch June 6, 2024 10:12
@fzaninotto fzaninotto added this to the 5.0.0 milestone Jun 6, 2024
@fzaninotto fzaninotto changed the title Fix types of Field components [TypeScript] Fix types of Field components Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants