@tanstack/form-core 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/FieldApi.ts CHANGED
@@ -119,8 +119,7 @@ type UnwrapFormValidateOrFnForInner<
119
119
  : undefined
120
120
 
121
121
  export type UnwrapFieldValidateOrFn<
122
- TParentData,
123
- TName extends DeepKeys<TParentData>,
122
+ TName extends string,
124
123
  TValidateOrFn extends undefined | FieldValidateOrFn<any, any, any>,
125
124
  TFormValidateOrFn extends undefined | FormValidateOrFn<any>,
126
125
  > =
@@ -202,8 +201,7 @@ type UnwrapFormAsyncValidateOrFnForInner<
202
201
  : undefined
203
202
 
204
203
  export type UnwrapFieldAsyncValidateOrFn<
205
- TParentData,
206
- TName extends DeepKeys<TParentData>,
204
+ TName extends string,
207
205
  TValidateOrFn extends undefined | FieldAsyncValidateOrFn<any, any, any>,
208
206
  TFormValidateOrFn extends undefined | FormAsyncValidateOrFn<any>,
209
207
  > =
@@ -446,31 +444,45 @@ export interface FieldOptions<
446
444
  * An object type representing the required options for the FieldApi class.
447
445
  */
448
446
  export interface FieldApiOptions<
449
- TParentData,
450
- TName extends DeepKeys<TParentData>,
451
- TData extends DeepValue<TParentData, TName>,
452
- TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
453
- TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
454
- TOnChangeAsync extends
447
+ in out TParentData,
448
+ in out TName extends DeepKeys<TParentData>,
449
+ in out TData extends DeepValue<TParentData, TName>,
450
+ in out TOnMount extends
451
+ | undefined
452
+ | FieldValidateOrFn<TParentData, TName, TData>,
453
+ in out TOnChange extends
454
+ | undefined
455
+ | FieldValidateOrFn<TParentData, TName, TData>,
456
+ in out TOnChangeAsync extends
455
457
  | undefined
456
458
  | FieldAsyncValidateOrFn<TParentData, TName, TData>,
457
- TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
458
- TOnBlurAsync extends
459
+ in out TOnBlur extends
460
+ | undefined
461
+ | FieldValidateOrFn<TParentData, TName, TData>,
462
+ in out TOnBlurAsync extends
459
463
  | undefined
460
464
  | FieldAsyncValidateOrFn<TParentData, TName, TData>,
461
- TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
462
- TOnSubmitAsync extends
465
+ in out TOnSubmit extends
466
+ | undefined
467
+ | FieldValidateOrFn<TParentData, TName, TData>,
468
+ in out TOnSubmitAsync extends
463
469
  | undefined
464
470
  | FieldAsyncValidateOrFn<TParentData, TName, TData>,
465
- TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
466
- TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
467
- TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
468
- TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
469
- TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
470
- TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
471
- TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
472
- TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
473
- TParentSubmitMeta,
471
+ in out TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
472
+ in out TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
473
+ in out TFormOnChangeAsync extends
474
+ | undefined
475
+ | FormAsyncValidateOrFn<TParentData>,
476
+ in out TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
477
+ in out TFormOnBlurAsync extends
478
+ | undefined
479
+ | FormAsyncValidateOrFn<TParentData>,
480
+ in out TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
481
+ in out TFormOnSubmitAsync extends
482
+ | undefined
483
+ | FormAsyncValidateOrFn<TParentData>,
484
+ in out TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
485
+ in out TParentSubmitMeta,
474
486
  > extends FieldOptions<
475
487
  TParentData,
476
488
  TName,
@@ -538,28 +550,13 @@ export type FieldMetaBase<
538
550
  * A map of errors related to the field value.
539
551
  */
540
552
  errorMap: ValidationErrorMap<
541
- UnwrapFieldValidateOrFn<TParentData, TName, TOnMount, TFormOnMount>,
542
- UnwrapFieldValidateOrFn<TParentData, TName, TOnChange, TFormOnChange>,
543
- UnwrapFieldAsyncValidateOrFn<
544
- TParentData,
545
- TName,
546
- TOnChangeAsync,
547
- TFormOnChangeAsync
548
- >,
549
- UnwrapFieldValidateOrFn<TParentData, TName, TOnBlur, TFormOnBlur>,
550
- UnwrapFieldAsyncValidateOrFn<
551
- TParentData,
552
- TName,
553
- TOnBlurAsync,
554
- TFormOnBlurAsync
555
- >,
556
- UnwrapFieldValidateOrFn<TParentData, TName, TOnSubmit, TFormOnSubmit>,
557
- UnwrapFieldAsyncValidateOrFn<
558
- TParentData,
559
- TName,
560
- TOnSubmitAsync,
561
- TFormOnSubmitAsync
562
- >
553
+ UnwrapFieldValidateOrFn<TName, TOnMount, TFormOnMount>,
554
+ UnwrapFieldValidateOrFn<TName, TOnChange, TFormOnChange>,
555
+ UnwrapFieldAsyncValidateOrFn<TName, TOnChangeAsync, TFormOnChangeAsync>,
556
+ UnwrapFieldValidateOrFn<TName, TOnBlur, TFormOnBlur>,
557
+ UnwrapFieldAsyncValidateOrFn<TName, TOnBlurAsync, TFormOnBlurAsync>,
558
+ UnwrapFieldValidateOrFn<TName, TOnSubmit, TFormOnSubmit>,
559
+ UnwrapFieldAsyncValidateOrFn<TName, TOnSubmitAsync, TFormOnSubmitAsync>
563
560
  >
564
561
  /**
565
562
  * A flag indicating whether the field is currently being validated.
@@ -617,40 +614,25 @@ export type FieldMetaDerived<
617
614
  */
618
615
  errors: Array<
619
616
  | UnwrapOneLevelOfArray<
620
- UnwrapFieldValidateOrFn<TParentData, TName, TOnMount, TFormOnMount>
617
+ UnwrapFieldValidateOrFn<TName, TOnMount, TFormOnMount>
621
618
  >
622
619
  | UnwrapOneLevelOfArray<
623
- UnwrapFieldValidateOrFn<TParentData, TName, TOnChange, TFormOnChange>
620
+ UnwrapFieldValidateOrFn<TName, TOnChange, TFormOnChange>
624
621
  >
625
622
  | UnwrapOneLevelOfArray<
626
- UnwrapFieldAsyncValidateOrFn<
627
- TParentData,
628
- TName,
629
- TOnChangeAsync,
630
- TFormOnChangeAsync
631
- >
623
+ UnwrapFieldAsyncValidateOrFn<TName, TOnChangeAsync, TFormOnChangeAsync>
632
624
  >
633
625
  | UnwrapOneLevelOfArray<
634
- UnwrapFieldValidateOrFn<TParentData, TName, TOnBlur, TFormOnBlur>
626
+ UnwrapFieldValidateOrFn<TName, TOnBlur, TFormOnBlur>
635
627
  >
636
628
  | UnwrapOneLevelOfArray<
637
- UnwrapFieldAsyncValidateOrFn<
638
- TParentData,
639
- TName,
640
- TOnBlurAsync,
641
- TFormOnBlurAsync
642
- >
629
+ UnwrapFieldAsyncValidateOrFn<TName, TOnBlurAsync, TFormOnBlurAsync>
643
630
  >
644
631
  | UnwrapOneLevelOfArray<
645
- UnwrapFieldValidateOrFn<TParentData, TName, TOnSubmit, TFormOnSubmit>
632
+ UnwrapFieldValidateOrFn<TName, TOnSubmit, TFormOnSubmit>
646
633
  >
647
634
  | UnwrapOneLevelOfArray<
648
- UnwrapFieldAsyncValidateOrFn<
649
- TParentData,
650
- TName,
651
- TOnSubmitAsync,
652
- TFormOnSubmitAsync
653
- >
635
+ UnwrapFieldAsyncValidateOrFn<TName, TOnSubmitAsync, TFormOnSubmitAsync>
654
636
  >
655
637
  >
656
638
  /**
@@ -858,31 +840,45 @@ export type AnyFieldApi = FieldApi<
858
840
  * the `new FieldApi` constructor.
859
841
  */
860
842
  export class FieldApi<
861
- TParentData,
862
- TName extends DeepKeys<TParentData>,
863
- TData extends DeepValue<TParentData, TName>,
864
- TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
865
- TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
866
- TOnChangeAsync extends
843
+ in out TParentData,
844
+ in out TName extends DeepKeys<TParentData>,
845
+ in out TData extends DeepValue<TParentData, TName>,
846
+ in out TOnMount extends
847
+ | undefined
848
+ | FieldValidateOrFn<TParentData, TName, TData>,
849
+ in out TOnChange extends
850
+ | undefined
851
+ | FieldValidateOrFn<TParentData, TName, TData>,
852
+ in out TOnChangeAsync extends
867
853
  | undefined
868
854
  | FieldAsyncValidateOrFn<TParentData, TName, TData>,
869
- TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
870
- TOnBlurAsync extends
855
+ in out TOnBlur extends
856
+ | undefined
857
+ | FieldValidateOrFn<TParentData, TName, TData>,
858
+ in out TOnBlurAsync extends
871
859
  | undefined
872
860
  | FieldAsyncValidateOrFn<TParentData, TName, TData>,
873
- TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
874
- TOnSubmitAsync extends
861
+ in out TOnSubmit extends
862
+ | undefined
863
+ | FieldValidateOrFn<TParentData, TName, TData>,
864
+ in out TOnSubmitAsync extends
875
865
  | undefined
876
866
  | FieldAsyncValidateOrFn<TParentData, TName, TData>,
877
- TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
878
- TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
879
- TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
880
- TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
881
- TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
882
- TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
883
- TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
884
- TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
885
- TParentSubmitMeta,
867
+ in out TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
868
+ in out TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
869
+ in out TFormOnChangeAsync extends
870
+ | undefined
871
+ | FormAsyncValidateOrFn<TParentData>,
872
+ in out TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
873
+ in out TFormOnBlurAsync extends
874
+ | undefined
875
+ | FormAsyncValidateOrFn<TParentData>,
876
+ in out TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
877
+ in out TFormOnSubmitAsync extends
878
+ | undefined
879
+ | FormAsyncValidateOrFn<TParentData>,
880
+ in out TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
881
+ in out TParentSubmitMeta,
886
882
  > {
887
883
  /**
888
884
  * A reference to the form API instance.
@@ -1315,10 +1311,7 @@ export class FieldApi<
1315
1311
  if (!field.instance) continue
1316
1312
  const { onChangeListenTo, onBlurListenTo } =
1317
1313
  field.instance.options.validators || {}
1318
- if (
1319
- cause === 'change' &&
1320
- onChangeListenTo?.includes(this.name as string)
1321
- ) {
1314
+ if (cause === 'change' && onChangeListenTo?.includes(this.name)) {
1322
1315
  linkedFields.push(field.instance)
1323
1316
  }
1324
1317
  if (cause === 'blur' && onBlurListenTo?.includes(this.name as string)) {
package/src/FormApi.ts CHANGED
@@ -236,16 +236,16 @@ export interface FormTransform<
236
236
  * An object representing the options for a form.
237
237
  */
238
238
  export interface FormOptions<
239
- TFormData,
240
- TOnMount extends undefined | FormValidateOrFn<TFormData>,
241
- TOnChange extends undefined | FormValidateOrFn<TFormData>,
242
- TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
243
- TOnBlur extends undefined | FormValidateOrFn<TFormData>,
244
- TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
245
- TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
246
- TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
247
- TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
248
- TSubmitMeta = never,
239
+ in out TFormData,
240
+ in out TOnMount extends undefined | FormValidateOrFn<TFormData>,
241
+ in out TOnChange extends undefined | FormValidateOrFn<TFormData>,
242
+ in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
243
+ in out TOnBlur extends undefined | FormValidateOrFn<TFormData>,
244
+ in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
245
+ in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
246
+ in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
247
+ in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
248
+ in out TSubmitMeta = never,
249
249
  > {
250
250
  /**
251
251
  * Set initial values for your form.
@@ -275,6 +275,10 @@ export interface FormOptions<
275
275
  * Optional time in milliseconds if you want to introduce a delay before firing off an async action.
276
276
  */
277
277
  asyncDebounceMs?: number
278
+ /**
279
+ * If true, allows the form to be submitted in an invalid state i.e. canSubmit will remain true regardless of validation errors. Defaults to undefined.
280
+ */
281
+ canSubmitWhenInvalid?: boolean
278
282
  /**
279
283
  * A list of validators to pass to the form
280
284
  */
@@ -393,15 +397,15 @@ export type FieldInfo<TFormData> = {
393
397
  * An object representing the current state of the form.
394
398
  */
395
399
  export type BaseFormState<
396
- TFormData,
397
- TOnMount extends undefined | FormValidateOrFn<TFormData>,
398
- TOnChange extends undefined | FormValidateOrFn<TFormData>,
399
- TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
400
- TOnBlur extends undefined | FormValidateOrFn<TFormData>,
401
- TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
402
- TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
403
- TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
404
- TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
400
+ in out TFormData,
401
+ in out TOnMount extends undefined | FormValidateOrFn<TFormData>,
402
+ in out TOnChange extends undefined | FormValidateOrFn<TFormData>,
403
+ in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
404
+ in out TOnBlur extends undefined | FormValidateOrFn<TFormData>,
405
+ in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
406
+ in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
407
+ in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
408
+ in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
405
409
  > = {
406
410
  /**
407
411
  * The current values of the form fields.
@@ -468,15 +472,15 @@ export type BaseFormState<
468
472
  }
469
473
 
470
474
  export type DerivedFormState<
471
- TFormData,
472
- TOnMount extends undefined | FormValidateOrFn<TFormData>,
473
- TOnChange extends undefined | FormValidateOrFn<TFormData>,
474
- TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
475
- TOnBlur extends undefined | FormValidateOrFn<TFormData>,
476
- TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
477
- TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
478
- TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
479
- TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
475
+ in out TFormData,
476
+ in out TOnMount extends undefined | FormValidateOrFn<TFormData>,
477
+ in out TOnChange extends undefined | FormValidateOrFn<TFormData>,
478
+ in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
479
+ in out TOnBlur extends undefined | FormValidateOrFn<TFormData>,
480
+ in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
481
+ in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
482
+ in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
483
+ in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
480
484
  > = {
481
485
  /**
482
486
  * A boolean indicating if the form is currently validating.
@@ -537,38 +541,38 @@ export type DerivedFormState<
537
541
  fieldMeta: Record<DeepKeys<TFormData>, AnyFieldMeta>
538
542
  }
539
543
 
540
- export type FormState<
541
- TFormData,
542
- TOnMount extends undefined | FormValidateOrFn<TFormData>,
543
- TOnChange extends undefined | FormValidateOrFn<TFormData>,
544
- TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
545
- TOnBlur extends undefined | FormValidateOrFn<TFormData>,
546
- TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
547
- TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
548
- TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
549
- TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
550
- > = BaseFormState<
551
- TFormData,
552
- TOnMount,
553
- TOnChange,
554
- TOnChangeAsync,
555
- TOnBlur,
556
- TOnBlurAsync,
557
- TOnSubmit,
558
- TOnSubmitAsync,
559
- TOnServer
560
- > &
561
- DerivedFormState<
562
- TFormData,
563
- TOnMount,
564
- TOnChange,
565
- TOnChangeAsync,
566
- TOnBlur,
567
- TOnBlurAsync,
568
- TOnSubmit,
569
- TOnSubmitAsync,
570
- TOnServer
571
- >
544
+ export interface FormState<
545
+ in out TFormData,
546
+ in out TOnMount extends undefined | FormValidateOrFn<TFormData>,
547
+ in out TOnChange extends undefined | FormValidateOrFn<TFormData>,
548
+ in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
549
+ in out TOnBlur extends undefined | FormValidateOrFn<TFormData>,
550
+ in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
551
+ in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
552
+ in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
553
+ in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
554
+ > extends BaseFormState<
555
+ TFormData,
556
+ TOnMount,
557
+ TOnChange,
558
+ TOnChangeAsync,
559
+ TOnBlur,
560
+ TOnBlurAsync,
561
+ TOnSubmit,
562
+ TOnSubmitAsync,
563
+ TOnServer
564
+ >,
565
+ DerivedFormState<
566
+ TFormData,
567
+ TOnMount,
568
+ TOnChange,
569
+ TOnChangeAsync,
570
+ TOnBlur,
571
+ TOnBlurAsync,
572
+ TOnSubmit,
573
+ TOnSubmitAsync,
574
+ TOnServer
575
+ > {}
572
576
 
573
577
  export type AnyFormState = FormState<
574
578
  any,
@@ -662,16 +666,16 @@ export type AnyFormApi = FormApi<
662
666
  * However, if you need to create a new instance manually, you can do so by calling the `new FormApi` constructor.
663
667
  */
664
668
  export class FormApi<
665
- TFormData,
666
- TOnMount extends undefined | FormValidateOrFn<TFormData>,
667
- TOnChange extends undefined | FormValidateOrFn<TFormData>,
668
- TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
669
- TOnBlur extends undefined | FormValidateOrFn<TFormData>,
670
- TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
671
- TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
672
- TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
673
- TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
674
- TSubmitMeta = never,
669
+ in out TFormData,
670
+ in out TOnMount extends undefined | FormValidateOrFn<TFormData>,
671
+ in out TOnChange extends undefined | FormValidateOrFn<TFormData>,
672
+ in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
673
+ in out TOnBlur extends undefined | FormValidateOrFn<TFormData>,
674
+ in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
675
+ in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
676
+ in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
677
+ in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
678
+ in out TSubmitMeta = never,
675
679
  > {
676
680
  /**
677
681
  * The options for the form.
@@ -943,11 +947,13 @@ export class FormApi<
943
947
 
944
948
  const isFormValid = errors.length === 0
945
949
  const isValid = isFieldsValid && isFormValid
950
+ const submitInvalid = this.options.canSubmitWhenInvalid ?? false
946
951
  const canSubmit =
947
952
  (currBaseStore.submissionAttempts === 0 &&
948
953
  !isTouched &&
949
954
  !hasOnMountError) ||
950
- (!isValidating && !currBaseStore.isSubmitting && isValid)
955
+ (!isValidating && !currBaseStore.isSubmitting && isValid) ||
956
+ submitInvalid
951
957
 
952
958
  let errorMap = currBaseStore.errorMap
953
959
  if (shouldInvalidateOnMount) {
@@ -1595,7 +1601,6 @@ export class FormApi<
1595
1601
  isSubmitSuccessful: false, // Reset isSubmitSuccessful at the start of submission
1596
1602
  }))
1597
1603
 
1598
- // Don't let invalid forms submit
1599
1604
  if (!this.state.canSubmit) return
1600
1605
 
1601
1606
  this.baseStore.setState((d) => ({ ...d, isSubmitting: true }))
package/src/util-types.ts CHANGED
@@ -19,132 +19,92 @@ type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch
19
19
  */
20
20
  export type Narrow<A> = Try<A, [], NarrowRaw<A>>
21
21
 
22
- type ComputeRange<
23
- N extends number,
24
- Result extends Array<unknown> = [],
25
- > = Result['length'] extends N
26
- ? Result
27
- : ComputeRange<N, [...Result, Result['length']]>
28
- type Index40 = ComputeRange<40>[number]
29
-
30
- // Is this type a tuple?
31
- type IsTuple<T> = T extends readonly any[] & { length: infer Length }
32
- ? Length extends Index40
22
+ type IsAny<T> = 0 extends 1 & T ? true : false
23
+
24
+ export type ArrayAccessor<TPrefix extends string> = `${TPrefix}[${number}]`
25
+
26
+ export type DeepRecordArrayUnion<
27
+ T extends ReadonlyArray<any>,
28
+ TPrefix extends string,
29
+ TAcc,
30
+ > = DeepRecordUnion<
31
+ T[number],
32
+ ArrayAccessor<TPrefix>,
33
+ TAcc | Record<ArrayAccessor<TPrefix>, T[number]>
34
+ >
35
+
36
+ export type TupleAccessor<
37
+ TPrefix extends string,
38
+ TKey,
39
+ > = `${TPrefix}[${TKey & string}]`
40
+
41
+ export type AllTupleKeys<T> = T extends any ? keyof T & `${number}` : never
42
+
43
+ export type DeepRecordTupleUnion<
44
+ T extends ReadonlyArray<any>,
45
+ TPrefix extends string,
46
+ TAcc,
47
+ TAllKeys extends AllTupleKeys<T> = AllTupleKeys<T>,
48
+ > = TAllKeys extends any
49
+ ? DeepRecordUnion<
50
+ T[TAllKeys],
51
+ TupleAccessor<TPrefix, TAllKeys>,
52
+ TAcc | Record<TupleAccessor<TPrefix, TAllKeys>, T[TAllKeys]>
53
+ >
54
+ : never
55
+
56
+ export type AllObjectKeys<T> = T extends any
57
+ ? keyof T & (string | number)
58
+ : never
59
+
60
+ export type ObjectAccessor<
61
+ TPrefix extends string,
62
+ TKey extends string | number,
63
+ > = TPrefix extends '' ? `${TKey}` : `${TPrefix}.${TKey}`
64
+
65
+ export type DeepRecordObjectUnion<
66
+ T,
67
+ TPrefix extends string,
68
+ TAcc,
69
+ TAllKeys extends AllObjectKeys<T> = AllObjectKeys<T>,
70
+ > = TAllKeys extends any
71
+ ? DeepRecordUnion<
72
+ T[TAllKeys],
73
+ ObjectAccessor<TPrefix, TAllKeys>,
74
+ TAcc | Record<ObjectAccessor<TPrefix, TAllKeys>, T[TAllKeys]>
75
+ >
76
+ : never
77
+
78
+ export type DeepRecordUnion<T, TPrefix extends string = '', TAcc = never> =
79
+ IsAny<T> extends true
33
80
  ? T
34
- : never
81
+ : T extends string | number | boolean | bigint | Date
82
+ ? TAcc
83
+ : T extends ReadonlyArray<any>
84
+ ? number extends T['length']
85
+ ? DeepRecordArrayUnion<T, TPrefix, TAcc>
86
+ : DeepRecordTupleUnion<T, TPrefix, TAcc>
87
+ : T extends object
88
+ ? DeepRecordObjectUnion<T, TPrefix, TAcc>
89
+ : TAcc
90
+
91
+ export type UnionToIntersection<T> = (
92
+ T extends any ? (param: T) => any : never
93
+ ) extends (param: infer TI) => any
94
+ ? TI
35
95
  : never
36
96
 
37
- // If this type is a tuple, what indices are allowed?
38
- type AllowedIndexes<
39
- Tuple extends ReadonlyArray<any>,
40
- Keys extends number = never,
41
- > = Tuple extends readonly []
42
- ? Keys
43
- : Tuple extends readonly [infer _, ...infer Tail]
44
- ? AllowedIndexes<Tail, Keys | Tail['length']>
45
- : Keys
46
-
47
- type PrefixArrayAccessor<T extends any[], TDepth extends any[]> = {
48
- [K in keyof T]: `[${number}]${DeepKeys<T[K], TDepth>}`
49
- }[number]
50
-
51
- type PrefixTupleAccessor<
52
- T extends any[],
53
- TIndex extends number,
54
- TDepth extends any[],
55
- > = {
56
- [K in TIndex]: `[${K}]` | `[${K}]${DeepKeys<T[K], TDepth>}`
57
- }[TIndex]
58
-
59
- type PrefixObjectAccessor<T extends object, TDepth extends any[]> = {
60
- [K in keyof T]-?: K extends string | number
61
- ?
62
- | PrefixFromDepth<K, TDepth>
63
- | `${PrefixFromDepth<K, TDepth>}${DeepKeys<T[K], [TDepth]>}`
64
- : never
65
- }[keyof T]
97
+ export type DeepRecord<T> = UnionToIntersection<DeepRecordUnion<T>>
66
98
 
67
99
  /**
68
100
  * The keys of an object or array, deeply nested.
69
101
  */
70
- export type DeepKeys<T, TDepth extends any[] = []> = TDepth['length'] extends 5
71
- ? never
72
- : unknown extends T
73
- ? PrefixFromDepth<string, TDepth>
74
- : T extends readonly any[] & IsTuple<T>
75
- ? PrefixTupleAccessor<T, AllowedIndexes<T>, TDepth>
76
- : T extends any[]
77
- ? PrefixArrayAccessor<T, [...TDepth, any]>
78
- : T extends Date
79
- ? never
80
- : T extends object
81
- ? PrefixObjectAccessor<T, TDepth>
82
- : T extends string | number | boolean | bigint
83
- ? ''
84
- : never
85
-
86
- type PrefixFromDepth<
87
- T extends string | number,
88
- TDepth extends any[],
89
- > = TDepth['length'] extends 0 ? T : `.${T}`
90
-
91
- // Hack changing Typescript's default get behavior in order to work with union objects
92
- type Get<T, K extends string> = T extends { [Key in K]: infer V }
93
- ? V
94
- : T extends { [Key in K]?: infer W }
95
- ? W | undefined
96
- : never
97
-
98
- type ApplyNull<T> = null extends T ? null : never
99
- type ApplyUndefined<T> = undefined extends T ? undefined : never
102
+ export type DeepKeys<T> = unknown extends T
103
+ ? string
104
+ : keyof DeepRecord<T> & string
100
105
 
101
106
  /**
102
107
  * Infer the type of a deeply nested property within an object or an array.
103
108
  */
104
- export type DeepValue<
105
- // The object or array in which we have the property whose type we're trying to infer
106
- TValue,
107
- // A string representing the path of the property we're trying to access
108
- TAccessor,
109
- // Depth for preventing infinite recursion
110
- TDepth extends ReadonlyArray<any> = [],
111
- > = unknown extends TValue // If TValue is any it will recurse forever, this terminates the recursion
112
- ? TValue
113
- : TDepth['length'] extends 10
114
- ? unknown
115
- : // Check if we're looking for the property in an array
116
- TValue extends ReadonlyArray<any>
117
- ? TAccessor extends `[${infer TBrackets}].${infer TAfter}`
118
- ? /*
119
- Extract the first element from the accessor path (`TBrackets`)
120
- and recursively call `DeepValue` with it
121
- */
122
- DeepValue<
123
- DeepValue<TValue, TBrackets, [...TDepth, any]>,
124
- TAfter,
125
- [...TDepth, any]
126
- >
127
- : TAccessor extends `[${infer TBrackets}]`
128
- ? DeepValue<TValue, TBrackets, [...TDepth, any]>
129
- : TAccessor extends keyof TValue
130
- ? TValue[TAccessor]
131
- : TValue[TAccessor & number]
132
- : TAccessor extends `${infer TBefore}[${infer TEverythingElse}`
133
- ? DeepValue<
134
- DeepValue<TValue, TBefore, [...TDepth, any]>,
135
- `[${TEverythingElse}`,
136
- [...TDepth, any]
137
- >
138
- : TAccessor extends `[${infer TBrackets}]`
139
- ? DeepValue<TValue, TBrackets, [...TDepth, any]>
140
- : TAccessor extends `${infer TBefore}.${infer TAfter}`
141
- ? DeepValue<
142
- DeepValue<TValue, TBefore, [...TDepth, any]>,
143
- TAfter,
144
- [...TDepth, any]
145
- >
146
- : TAccessor extends string
147
- ?
148
- | Get<TValue, TAccessor>
149
- | (ApplyNull<TValue> | ApplyUndefined<TValue>)
150
- : never
109
+ export type DeepValue<TValue, TAccessor> = DeepRecord<TValue>[TAccessor &
110
+ keyof DeepRecord<TValue>]