Shopify / quilt

A loosely related set of packages for JavaScript/TypeScript projects at Shopify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expanding `FieldBag` and `useForm`

AntanasGa opened this issue · comments

Overview

When working on projects i expect some types to be shared between back end and front end, meaning that if i want the type to change in one, I'll have to check over the other.

the suggested changes would be:

export function useForm<
  T extends object,
  V extends FieldBag = T extends FieldBag
    ? T
    : {
        [K in keyof T]: FieldOutput<T[K]>;
      },
>({
  fields,
  onSubmit,
  makeCleanAfterSubmit,
}: FormWithoutDynamicListsInput<V>): Form<V>;
export type FieldOutput<T> = T extends object
  ? T extends any[]
    ? FieldDictionary<T>[]
    : FieldDictionary<T>
  : Field<T>;

Type

  • New feature
  • Changes to existing features