TanStackT
TanStack3mo ago
15 replies
faint-white

`withForm` and `withFieldGroup` types for `render` and `props`

I have 2 questions.

Question 1


Is there any reason why TRenderProps in withForm and withFieldGroup are different?

Current state:
withForm: TRenderProps extends object = Record<string, never>
withFieldGroup: TRenderProps extends Record<string, unknown> = Record<string, never>

My use-case:

interface ComponentPropsInterface {
  label?: string
}

type ComponentPropsType = {
  label?: string
}

// works
withForm({
  props: {} as ComponentPropsInterface
})

// Index signature for type 'string' is missing in type 'Props'.
withFieldGroup({
  props: {} as ComponentPropsInterface
})

// works
withFieldGroup({
  props: {} as ComponentPropsType
})

// also works
withFieldGroup({
  props: {} as { label?: string }
})


Question 2


Is there any reason why the return type of
render
is JSX.Element only instead of ReactNode for example?

My use-case:

// Type 'null' is not assignable to type 'ReactElement<any, any>'.
withForm({
  render: function Render() {
    if (condition) return null

    return <div />
  },
})


I can do return <></> and that fixes it, but still...
Was this page helpful?