question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] typescript FieldRenderProps do not include custom props passed to Field

See original GitHub issue

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

The typescript defs assume that only FieldRenderProps are passed to component, render, and children (https://github.com/final-form/react-final-form/blob/master/src/index.d.ts#L58-L69) when in fact FieldRenderProps AND “any non-API props passed into the <Field/> component” are passed to component, render, and children.

This results in type errors when custom props passed to Field are required by the component:

Property ‘label’ is missing in type ‘FieldRenderProps & { children?: ReactNode; }’.

23:11 Type '{ name: string; component: (props: FieldLayoutProps) => Element; label: string; Control: string; }' is not assignable to type 'IntrinsicAttributes & FieldProps & { children?: ReactNode; }'.
  Type '{ name: string; component: (props: FieldLayoutProps) => Element; label: string; Control: string; }' is not assignable to type 'FieldProps'.
    Types of property 'component' are incompatible.
      Type '(props: FieldLayoutProps) => Element' is not assignable to type 'string | ComponentClass<FieldRenderProps> | StatelessComponent<FieldRenderProps> | undefined'.
        Type '(props: FieldLayoutProps) => Element' is not assignable to type 'StatelessComponent<FieldRenderProps>'.
          Types of parameters 'props' and 'props' are incompatible.
            Type 'FieldRenderProps & { children?: ReactNode; }' is not assignable to type 'FieldLayoutProps'.
              Property 'label' is missing in type 'FieldRenderProps & { children?: ReactNode; }'.
    21 |       <div>
    22 |         <Field
  > 23 |           name="user.name"
       |           ^
    24 |           component={FieldLayout}
    25 |           label="Full Name"
    26 |           Control="input"

…assume FieldLayoutProps is minimally defined as:

export interface FieldLayoutProps extends FieldRenderProps {
  label: string;
  Control: string;
}

What is the expected behavior?

The typescript defs include “any non-API props passed into the <Field/> component” in FieldRenderProps so that there is no compile-time type error when component requires props passed to Field.

This would match:

  1. the docs: https://github.com/final-form/react-final-form#children-props-fieldrenderprops--reactnode--reactnode
  2. the runtime behavior: https://github.com/final-form/react-final-form/blob/master/src/Field.js#L161-L172

What’s your environment?

react-final-form@3.1.0, typescript@2.7.1

using the tsc compiler options noImplicitAny and strictNullChecks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:22
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
leonid-shevtsovcommented, Feb 10, 2019

A workaround I’ve found is to declare custom props optional (and add a big FIXME)

// FIXME making custom props optional until this is resolved: 
// https://github.com/final-form/react-final-form/issues/175
export interface FieldLayoutProps extends FieldRenderProps {
  label?: string;
  Control?: string;
}
3reactions
ebrillhartcommented, Jan 4, 2019

We are also encountering this problem and would very much appreciate a fix or workaround suggestions

Read more comments on GitHub >

github_iconTop Results From Across the Web

[bug] typescript FieldRenderProps do not include custom props ...
Property 'label' is missing in type 'FieldRenderProps & { children?: ReactNode; }'. ... What is the expected behavior? The typescript defs include "any...
Read more >
conflict when extends interface with react-final-form ...
I try to create custom react function component to pass it to react-final-form Field as a component but get an error. details. The...
Read more >
Final Form Docs – `FieldProps`
A render function that is given FieldRenderProps , as well as any non-API props passed into the <Field/> component. For example, if you...
Read more >
FieldRenderProps - React Form Component - KendoReact API
FieldRenderProps. Represents the props that are passed to the component which is rendered by Field. Name, Type, Default, Description ...
Read more >
react-final-form - npm
A render function that is given FieldRenderProps , children prop, as well as any non-API props passed into the <Field/> component. subscription ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found