Skip to content

Commit de23429

Browse files
committed
Using T instead of UnwrappedT.
1 parent b2e1946 commit de23429

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/lib/client/index.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,14 @@ export function superForm<
313313
| string,
314314
options: FormOptions<UnwrapEffects<T>, M> = {}
315315
): SuperForm<UnwrapEffects<T>, M> {
316-
type T2 = UnwrapEffects<T>;
316+
type UnwrappedT = UnwrapEffects<T>;
317317

318318
// Option guards
319319
{
320-
options = { ...(defaultFormOptions as FormOptions<T2, M>), ...options };
320+
options = {
321+
...(defaultFormOptions as FormOptions<UnwrappedT, M>),
322+
...options
323+
};
321324

322325
if (typeof form === 'string' && typeof options.id === 'string') {
323326
throw new SuperFormError(
@@ -343,7 +346,7 @@ export function superForm<
343346
postedForm
344347
).reverse()) {
345348
if (superForm.id === _formId) {
346-
form = superForm as Validation<T2, M>;
349+
form = superForm as Validation<T, M>;
347350
break;
348351
}
349352
}
@@ -356,7 +359,7 @@ export function superForm<
356359
form = Context_newEmptyForm(form); // Takes care of Partial<z.infer<T>>
357360
}
358361

359-
const form2 = form as Validation<T2, M>;
362+
const form2 = form as Validation<T, M>;
360363

361364
// Need to clone the validation data, in case it's used to populate multiple forms.
362365
const initialForm = clone(form2);
@@ -383,13 +386,13 @@ export function superForm<
383386

384387
function Context_newEmptyForm(
385388
data: Partial<z.infer<T>> = {}
386-
): Validation<T2, M> {
389+
): Validation<T, M> {
387390
return {
388391
valid: false,
389392
errors: {},
390393
data,
391394
empty: true,
392-
constraints: {} as Validation<T2, M>['constraints']
395+
constraints: {} as Validation<T, M>['constraints']
393396
};
394397
}
395398

@@ -490,7 +493,7 @@ export function superForm<
490493
}
491494

492495
async function Form_updateFromValidation(
493-
form: Validation<T2, M>,
496+
form: Validation<T, M>,
494497
untaint: boolean
495498
) {
496499
if (
@@ -556,7 +559,7 @@ export function superForm<
556559
for (const newForm of forms) {
557560
if (newForm.id !== _formId) continue;
558561
await Form_updateFromValidation(
559-
newForm as Validation<T2, M>,
562+
newForm as Validation<T, M>,
560563
untaint ?? (result.status >= 200 && result.status < 300)
561564
);
562565
}
@@ -567,7 +570,7 @@ export function superForm<
567570
const Empty = writable(form2.empty);
568571
const Message = writable<M | undefined>(form2.message);
569572
const Constraints = writable(form2.constraints);
570-
const Meta = writable<Validation<T2, M>['meta'] | undefined>(form2.meta);
573+
const Meta = writable<Validation<T, M>['meta'] | undefined>(form2.meta);
571574

572575
// eslint-disable-next-line dci-lint/grouped-rolemethods
573576
const Errors = {
@@ -585,7 +588,7 @@ export function superForm<
585588
})
586589
};
587590

588-
const Tainted = writable<TaintedFields<T2> | undefined>();
591+
const Tainted = writable<TaintedFields<UnwrappedT> | undefined>();
589592

590593
function Tainted_data() {
591594
return get(Tainted);
@@ -716,8 +719,8 @@ export function superForm<
716719
}
717720

718721
function rebind(
719-
form: Validation<T2, M>,
720-
untaint: TaintedFields<T2> | boolean,
722+
form: Validation<T, M>,
723+
untaint: TaintedFields<UnwrappedT> | boolean,
721724
message?: M
722725
) {
723726
if (untaint) {
@@ -747,7 +750,7 @@ export function superForm<
747750
}
748751
}
749752

750-
const formEvents: SuperFormEventList<T2, M> = {
753+
const formEvents: SuperFormEventList<UnwrappedT, M> = {
751754
onSubmit: options.onSubmit ? [options.onSubmit] : [],
752755
onResult: options.onResult ? [options.onResult] : [],
753756
onUpdate: options.onUpdate ? [options.onUpdate] : [],
@@ -793,7 +796,7 @@ export function superForm<
793796
if (/*newForm === form ||*/ newForm.id !== _formId) continue;
794797

795798
await Form_updateFromValidation(
796-
newForm as Validation<T2, M>,
799+
newForm as Validation<T, M>,
797800
untaint
798801
);
799802
}
@@ -806,7 +809,7 @@ export function superForm<
806809
//console.log('🚀 ~ PageData ~ newForm:', newForm.id);
807810
if (/*newForm === form ||*/ newForm.id !== _formId) continue;
808811

809-
rebind(newForm as Validation<T2, M>, untaint);
812+
rebind(newForm as Validation<T, M>, untaint);
810813
}
811814
}
812815
})
@@ -826,7 +829,7 @@ export function superForm<
826829
}
827830
];
828831
})
829-
) as unknown as FormFields<T2>;
832+
) as unknown as FormFields<UnwrappedT>;
830833

831834
return {
832835
form: Form,
@@ -862,7 +865,7 @@ export function superForm<
862865
};
863866
},
864867

865-
restore: function (snapshot: SuperFormSnapshot<T2, M>) {
868+
restore: function (snapshot: SuperFormSnapshot<UnwrappedT, M>) {
866869
return rebind(snapshot, snapshot.tainted ?? true);
867870
},
868871

@@ -877,7 +880,10 @@ export function superForm<
877880
opts
878881
);
879882
},
880-
enhance: (el: HTMLFormElement, events?: SuperFormEvents<T2, M>) => {
883+
enhance: (
884+
el: HTMLFormElement,
885+
events?: SuperFormEvents<UnwrappedT, M>
886+
) => {
881887
if (events) {
882888
if (events.onError) {
883889
if (options.onError === 'apply') {

0 commit comments

Comments
 (0)