Skip to content

FieldRenderProps type incorrectly includes an index signature #990

Open

Description

@jsonunger

Are you submitting a bug report or a feature request?

What is the current behavior?

FieldRenderProps includes an index signature that incorrectly assumes the matching object can have any number of fields beyond input and meta. If you define a component whose props extend FieldRenderProps, you end up including the index signature which allows any prop to be passed into the component even if it is untyped and unused. This is not type safe and can result in missed prop handling.

What is the expected behavior?

FieldRenderProps should not have an index signature included in its type since input and meta are the only two values explicitly defined within the field.

Sandbox Link

TypeScript sandbox with incorrect behavior

What's your environment?

React Final Form v6.5.9
Final Form v4.20.7
TypeScript v4.6.2

Other information

The FieldRenderProps interface includes an index signature. However, this index signature is unnecessary to how the type is used and results in poor type safety when used.

The interface is used for two pieces of the API, the Field component and the useField hook.

The useField type returns FieldRenderProps but the code explicitly returns only input and meta. Thus, the index signature serves no purpose here.

The Field component uses FieldRenderProps to ensure that the props of the rendered component extend FieldRenderProps. In this context, the index signature also doesn't provide any benefit because a type with extra props will still extend FieldRenderProps (example TS sandbox)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions