Skip to content

Commit eb8903e

Browse files
committed
Fixed default for FormOptions.
1 parent 14a8f76 commit eb8903e

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
- Type for `onChange.paths` wasn't strongly typed to `FormPath`.
1818
- Initial data was dereferenced after calling `superForm`, so it wasn't possible to update it when using `reset`.
19+
- `FormOptions` type required one type parameter that should've been defaulted to `Record<string, unknown>`.
1920

2021
## [2.4.0] - 2024-02-20
2122

src/lib/client/superForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type ValidatorsOption<T extends Record<string, unknown>> =
6868
// since SuperForm<A|B> is not the same as SuperForm<A> | SuperForm<B>
6969
// https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
7070
export type FormOptions<
71-
T extends Record<string, unknown>,
71+
T extends Record<string, unknown> = Record<string, unknown>,
7272
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7373
M = any,
7474
In extends Record<string, unknown> = T
@@ -354,7 +354,7 @@ const defaultFormOptions = {
354354
multipleSubmits: 'prevent',
355355
SPA: undefined,
356356
validationMethod: 'auto'
357-
} satisfies FormOptions<Record<string, unknown>, unknown>;
357+
} satisfies FormOptions;
358358

359359
function multipleFormIdError(id: string | undefined) {
360360
return (

src/routes/(v2)/v2/issue-337-checkboxes/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
onChange({ paths, set, get }) {
1111
for (const path of paths) {
1212
if (path == 'accept') {
13+
// @ts-expect-error Type error
14+
set('extra', 'a string', { taint: false });
1315
set('extra', 12, { taint: false });
1416
} else if (path == 'extra') {
1517
if (get(path) == 12) {

src/tests/superForm.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { zod } from '$lib/adapters/zod.js';
2-
import { fieldProxy, superForm, type SuperForm } from '$lib/client/index.js';
2+
import { fieldProxy, superForm, type FormOptions, type SuperForm } from '$lib/client/index.js';
33
import { superValidate, type SuperValidated } from '$lib/superValidate.js';
44
import { get } from 'svelte/store';
55
import { merge } from 'ts-deepmerge';
@@ -302,6 +302,27 @@ describe('Modifying initial data for updating reset', () => {
302302
});
303303
});
304304

305+
describe('FormOptions', () => {
306+
it('should work with default type parameters', async () => {
307+
const opts: FormOptions = {
308+
delayMs: 800,
309+
dataType: 'json'
310+
};
311+
312+
const validated = await superValidate(
313+
zod(
314+
z.object({
315+
name: z.string()
316+
})
317+
)
318+
);
319+
320+
const form = superForm(validated, opts);
321+
const delay: number | undefined = form.options.delayMs;
322+
expect(delay).toBe(800);
323+
});
324+
});
325+
305326
///// mockSvelte.ts (must be copy/pasted here) ////////////////////////////////
306327

307328
import { vi } from 'vitest';

0 commit comments

Comments
 (0)