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

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

Closed
mxdubois opened this issue Mar 1, 2018 · 8 comments · Fixed by #565
Closed

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

mxdubois opened this issue Mar 1, 2018 · 8 comments · Fixed by #565

Comments

@mxdubois
Copy link

mxdubois commented Mar 1, 2018

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 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 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

@randytorres
Copy link

any update on this?

@trejster
Copy link

Also have the same issue - any update?

@poteirard
Copy link

Is there a reason we are not using HTMLInputElement (from node_modules/typescript/lib/lib.dom.d.ts) for typing the input props?

@ebrillhart
Copy link

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

@leonid-shevtsov
Copy link

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;
}

@zalishchuk
Copy link

@erikras what is the current behaviour to use custom Field component prop with component whose props differ from FieldRenderProps in Typescript? I want to control the component passed to Field props, so making the props optional is not an option. Can we somehow pass props directly to Field if component prop is defined?

@Yankovsky
Copy link

@erikras any info about when it will be published?
Thanks for your great work by the way.

@erikras
Copy link
Member

erikras commented Nov 18, 2019

Published fix in v6.3.1.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants