react-final-form-arrays icon indicating copy to clipboard operation
react-final-form-arrays copied to clipboard

Unused type argument in FieldArrayRenderProps

Open dominikdosoudil opened this issue 2 years ago • 0 comments

Are you submitting a bug report or a feature request?

TS typing dead code

What is the current behavior?

interface FieldArrayRenderProps requires 2 generic arguments however the second one is unused.

What is the expected behavior?

interface FieldArrayRenderProps requires only one generic argument which represents value type.

Sandbox Link

https://codesandbox.io/s/react-final-form-field-arrays-forked-7wuwcb?file=/index.tsx

What's your environment?

    "final-form": "4.20.7",
    "final-form-arrays": "3.0.2",
    "react": "16.8.6",
    "react-dom": "16.8.6",
    "react-final-form": "6.5.9",
    "react-final-form-arrays": "3.1.4"

Other information

When you take a look at the interface, the second type argument is never used. Therefore it's useless. I think that it should be removed however it would be breaking change since the generic interface might be already used with 2 arguments in other projects. Removing the second type argument would cause error TS2314: Generic type 'FieldArrayRenderProps ' requires 1 type argument(s)..

export interface FieldArrayRenderProps<FieldValue, T extends HTMLElement> {
  fields: {
    forEach: (iterator: (name: string, index: number) => void) => void
    insert: (index: number, value: FieldValue) => void
    map: <R>(iterator: (name: string, index: number) => R) => R[]
    move: (from: number, to: number) => void
    update: (index: number, value: FieldValue) => void
    name: string
    pop: () => FieldValue
    push: (value: FieldValue) => void
    remove: (index: number) => FieldValue
    shift: () => FieldValue
    swap: (indexA: number, indexB: number) => void
    unshift: (value: FieldValue) => void
    value: FieldValue[]
  } & FieldState<FieldValue[]>
  meta: Partial<{
    // TODO: Make a diff of `FieldState` without all the functions
    active: boolean
    dirty: boolean
    dirtySinceLastSubmit: boolean
    error: any
    initial: any
    invalid: boolean
    pristine: boolean
    submitError: any
    submitFailed: boolean
    submitSucceeded: boolean
    touched: boolean
    valid: boolean
    visited: boolean
  }>
}

dominikdosoudil avatar Nov 02 '22 08:11 dominikdosoudil