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

FieldRenderProps type incorrectly includes an index signature #990

Open
jsonunger opened this issue May 9, 2022 · 0 comments
Open

FieldRenderProps type incorrectly includes an index signature #990

jsonunger opened this issue May 9, 2022 · 0 comments

Comments

@jsonunger
Copy link

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)

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

No branches or pull requests

1 participant