Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

debugging.md

68 lines2.1 KB

1---
2id: debugging
3title: Debugging Svelte Usage
4---
5​
6This page covers common Svelte and TypeScript problems when using TanStack
7Form.
8​
9## An input does not start with the expected value
10​
11Every value rendered by an input should exist in form-level `defaultValues`
12when the form is created.
13​
14```svelte
15<script lang="ts">
16 import { createForm } from '@tanstack/svelte-form'
17​
18 const form = createForm(() => ({
19 defaultValues: {
20 firstName: '',
21 subscribed: false,
22 },
23 }))
24</script>
25```
26​
27Do not omit `defaultValues` or rely on a field-level default. When values come
28from an API, render a loading state before mounting the editable form or supply
29a complete fallback shape.
30​
31## A field value is `unknown`
32​
33Field names and values are inferred from `defaultValues`. Check that you have
34not widened the initial object to `Record<string, unknown>`, `any`, or an
35unrelated union. Prefer a concrete value type:
36​
37```svelte
38<script lang="ts">
39 import { createForm } from '@tanstack/svelte-form'
40​
41 type Profile = { firstName: string; age: number }
42​
43 const defaults: Profile = { firstName: '', age: 0 }
44 const form = createForm(() => ({ defaultValues: defaults }))
45</script>
46```
47​
48For extremely large forms, split UI into typed components or scoped form and
49field groups instead of casting each field value.
50​
51## Type instantiation is excessively deep
52​
53This TypeScript error usually involves a very large recursive value shape, a
54widely inferred union, or an unsupported composition. Reduce it to the smallest
55form that reproduces the problem, keep `defaultValues` concrete, and avoid
56unnecessary generic wrappers.
57​
58If the minimal reproduction still fails, report it in the
59[TanStack Form issue tracker](https://github.com/TanStack/form/issues). Include
60the TypeScript and Svelte versions, the form value type, and the smallest
61failing field.
62​
63## Errors exist but are not displayed
64​
65`field.errors` respects the form's `errorVisibility` policy. Inspect
66`field.meta.original.errors` when debugging whether validation ran but the
67issues are intentionally hidden. Also confirm that the input calls
68`field.handleBlur` if the policy depends on `isBlurred`.