Skip to content

fix(types): remove void from SharedRenderProps component type#4064

Open
cyphercodes wants to merge 1 commit intojaredpalmer:mainfrom
cyphercodes:fix-shared-render-props-type
Open

fix(types): remove void from SharedRenderProps component type#4064
cyphercodes wants to merge 1 commit intojaredpalmer:mainfrom
cyphercodes:fix-shared-render-props-type

Conversation

@cyphercodes
Copy link
Copy Markdown

Summary

Fixes #4061

The component prop in SharedRenderProps interface had an incorrect TypeScript type that included void in the union (React.ComponentType<T | void>). This caused TypeScript errors when using properly typed components with FieldArray or other components using SharedRenderProps.

Problem

When using the component prop with a properly typed component, TypeScript produced false errors because it expected the component to accept void as props:

interface MyComponentProps {
  form: FormikProps<any>;
  name: string;
  push: (obj: any) => void;
}

const MyComponent: React.FC<MyComponentProps> = (props) => { ... };

// TypeScript error: Type 'FC<MyComponentProps>' is not assignable to type 'ComponentType<FieldArrayRenderProps | void>'
<FieldArray name="items" component={MyComponent} />

Solution

The component always receives the props of type T at runtime - there's no code path where it receives void. The type has been corrected to React.ComponentType<T>.

Changes

  • Changed React.ComponentType<T | void> to React.ComponentType<T> in SharedRenderProps interface

Verification

  • TypeScript compilation passes
  • No breaking changes - this is a type fix that makes the types match runtime behavior

The component prop in SharedRenderProps interface had an incorrect TypeScript
type that included void in the union (React.ComponentType<T | void>). This
caused TypeScript errors when using properly typed components with FieldArray
or other components using SharedRenderProps.

The component always receives the props of type T at runtime - there's no
code path where it receives void. The type has been corrected to
React.ComponentType<T>.

Fixes jaredpalmer#4061
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

@cyphercodes is attempting to deploy a commit to the Formik Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 28, 2026

⚠️ No Changeset found

Latest commit: e09f21f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codesandbox-ci
Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TypeScript] SharedRenderProps.component has incorrect type React.ComponentType<T | void> instead of React.ComponentType<T>

1 participant