@@ -168,6 +168,52 @@ let map_type_decl
168168 ]
169169 in
170170 let type_decls3 =
171+ Str. type_ Recursive
172+ [
173+ (* type fieldDirtyOfInputs = { example: bool, exampleRequired: bool, cart?: array<fieldDirtyOfItem> } *)
174+ Type. mk
175+ (mkloc (" fieldDirtyOf" ^ capitalize record_name) ptype_loc)
176+ ~priv: Public
177+ ~kind:
178+ (Ptype_record
179+ (lds
180+ |> List. map
181+ (fun (({ pld_type } : label_declaration ) as ld ) ->
182+ match pld_type with
183+ (* type fieldDirtyOfInputs = {cart?: array<fieldDirtyOfItem>} *)
184+ | {
185+ ptyp_desc =
186+ Ptyp_constr
187+ ( { txt = Lident " array" },
188+ [
189+ {
190+ ptyp_desc =
191+ Ptyp_constr ({ txt = Lident l }, [] );
192+ };
193+ ] );
194+ } ->
195+ {
196+ ld with
197+ pld_type =
198+ Typ. constr (lid " array" )
199+ [
200+ Typ. constr
201+ (lid @@ " fieldDirtyOf" ^ capitalize l)
202+ [];
203+ ];
204+ pld_attributes =
205+ add_optional_attribute ld.pld_attributes;
206+ }
207+ | _ ->
208+ {
209+ ld with
210+ pld_type = Typ. constr (lid " bool" ) [] ;
211+ pld_attributes =
212+ add_optional_attribute ld.pld_attributes;
213+ })));
214+ ]
215+ in
216+ let type_decls4 =
171217 Str. type_ Recursive
172218 [
173219 (* type useFormReturnOfInputs<'setValueAs> = {
@@ -331,7 +377,7 @@ let map_type_decl
331377 (mkloc (" variantOf" ^ capitalize record_name) ptype_loc)
332378 ~priv: Public
333379 ~kind: (Ptype_variant (make_const_decls fields ptype_loc));
334- (* type registerOptionsOfInputs<'setValueAs> = {required?: bool, setValueAs?: 'setValueAs} *)
380+ (* type registerOptionsOfInputs<'setValueAs> = {required?: bool, setValueAs?: 'setValueAs, valueAsNumber?: bool } *)
335381 Type. mk
336382 (mkloc (" registerOptionsOf" ^ capitalize record_name) ptype_loc)
337383 ~params: [ (Typ. var " setValueAs" , (NoVariance , NoInjectivity )) ]
@@ -344,8 +390,16 @@ let map_type_decl
344390 (Typ. constr (lid " bool" ) [] );
345391 Type. field ~attrs: [ attr_optional ] ~mut: Immutable
346392 (mknoloc " setValueAs" ) (Typ. var " setValueAs" );
393+ Type. field ~attrs: [ attr_optional ] ~mut: Immutable
394+ (mknoloc " valueAsNumber" )
395+ (Typ. constr (lid " bool" ) [] );
347396 ]);
348- (* type formStateOfInputs = {isDirty: bool, isValid: bool, errors: fieldErrorsOfInputs} *)
397+ (* type formStateOfInputs = {
398+ isDirty: bool,
399+ isValid: bool,
400+ errors: fieldErrorsOfInputs,
401+ dirtyFields: fieldDirtyOfInputs,
402+ } *)
349403 Type. mk
350404 (mkloc (" formStateOf" ^ capitalize record_name) ptype_loc)
351405 ~priv: Public
@@ -360,6 +414,10 @@ let map_type_decl
360414 (Typ. constr
361415 (lid @@ " fieldErrorsOf" ^ capitalize record_name)
362416 [] );
417+ Type. field ~mut: Immutable (mknoloc " dirtyFields" )
418+ (Typ. constr
419+ (lid @@ " fieldDirtyOf" ^ capitalize record_name)
420+ [] );
363421 ]);
364422 (* type fieldErrorsOfInputs = { example: fieldErrorOfInputs, exampleRequired: fieldErrorOfInputs } *)
365423 Type. mk
@@ -605,7 +663,7 @@ let map_type_decl
605663 disabled: bool=?,
606664 exact: bool=?,
607665 } *)
608- let type_decls4 =
666+ let type_decls5 =
609667 Str. type_ Recursive
610668 [
611669 Type. mk
@@ -669,7 +727,7 @@ let map_type_decl
669727 ]))
670728 in
671729
672- let type_decls5 =
730+ let type_decls6 =
673731 lds
674732 |> List. filter_map
675733 (fun
@@ -1056,12 +1114,13 @@ let map_type_decl
10561114 type_decls1;
10571115 type_decls2;
10581116 type_decls3;
1117+ type_decls4;
10591118 primitive_use_form;
10601119 module_controller;
1061- type_decls4 ;
1120+ type_decls5 ;
10621121 primitive_use_watch;
10631122 ]
1064- @ type_decls5 @ primitive_use_field_array @ vb_field_array
1123+ @ type_decls6 @ primitive_use_field_array @ vb_field_array
10651124 | _ -> fail ptype_loc " This type is not handled by @ppx_react_hook_form"
10661125 else []
10671126
0 commit comments