TanStackT
TanStack10mo ago
34 replies
continuing-aqua

Questions regarding migration to 1.x

Hello, I'm migrating from 0.35 to the latest.

In my react app, I have a lot of forms that are passed as props so I usually need to type them.

I used to do so with:
export type FormType<T> = FormApi<T, Validator<T>> &
  ReactFormApi<T, Validator<T>>;

So that I could do:
type Props = {
  form: FromType<MyFormType>
}

//Then stuff like form.Field, form.state.value, etc...

But now that validators are gone and that FormApi seemingly changed, I'm struggling to find the correct way to get similar behavior.

The closest I could find by sheer trial and error is:
export type FormType<T> = ReactFormExtendedApi<
  T,
  any,
  any,
  any,
  any,
  any,
  any,
  any,
  any,
  any
>;


but it seems to cause problems and might not be the best.

For example if I want to have a component that can take any Form:

type Props = {
  form: FormType<any>
}


And then try to use it, I get:
Type 'ReactFormExtendedApi</*fields in my schema*/>' is not assignable to type 'FormType<any>'.


The validator changes also seemed to break things, as I now get a type error whenever I have a form with default values and a schema with optional values, even when they should be/were compatible.

Sorry if this is a bit rambly but since this is so new I've had little chance to find answers/examples online ,especially as some of the official examples seem down.
Was this page helpful?