@tanstack/form-core 0.23.2 → 0.23.3

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.
@@ -1,149 +0,0 @@
1
- import { assertType, it } from 'vitest'
2
- import { FormApi } from '../FormApi'
3
- import { FieldApi } from '../FieldApi'
4
-
5
- it('should type value properly', () => {
6
- const form = new FormApi({
7
- defaultValues: {
8
- name: 'test',
9
- },
10
- } as const)
11
-
12
- const field = new FieldApi({
13
- form,
14
- name: 'name',
15
- })
16
-
17
- assertType<'test'>(field.state.value)
18
- assertType<'name'>(field.options.name)
19
- assertType<'test'>(field.getValue())
20
- })
21
-
22
- it('should type value when nothing is passed into constructor', () => {
23
- type FormValues = {
24
- name?: string
25
- age?: number
26
- }
27
-
28
- const form = new FormApi<FormValues>()
29
-
30
- const field = new FieldApi({
31
- form,
32
- name: 'name' as const,
33
- })
34
-
35
- assertType<string | undefined>(field.state.value)
36
- assertType<'name'>(field.options.name)
37
- assertType<string | undefined>(field.getValue())
38
- })
39
-
40
- it('should type required fields in constructor', () => {
41
- type FormValues = {
42
- name: string
43
- age?: number
44
- }
45
-
46
- const form = new FormApi<FormValues>({
47
- defaultValues: {
48
- name: 'test',
49
- },
50
- })
51
-
52
- const field = new FieldApi({
53
- form,
54
- name: 'name' as const,
55
- })
56
-
57
- assertType<string>(field.state.value)
58
- assertType<'name'>(field.options.name)
59
- assertType<string>(field.getValue())
60
- })
61
-
62
- it('should type value properly for completely partial forms', () => {
63
- type CompletelyPartialFormValues = {
64
- name?: 'test'
65
- age?: number
66
- }
67
-
68
- const form = new FormApi<CompletelyPartialFormValues>({
69
- defaultValues: {},
70
- })
71
-
72
- const field = new FieldApi({
73
- form,
74
- name: 'name' as const,
75
- })
76
-
77
- assertType<'test' | undefined>(field.state.value)
78
- assertType<'name'>(field.options.name)
79
- assertType<'test' | undefined>(field.getValue())
80
- })
81
-
82
- it('should type onChange properly', () => {
83
- const form = new FormApi({
84
- defaultValues: {
85
- name: 'test',
86
- },
87
- } as const)
88
-
89
- const field = new FieldApi({
90
- form,
91
- name: 'name',
92
- validators: {
93
- onChange: ({ value }) => {
94
- assertType<'test'>(value)
95
-
96
- return undefined
97
- },
98
- },
99
- })
100
- })
101
-
102
- it('should type onChangeAsync properly', () => {
103
- const form = new FormApi({
104
- defaultValues: {
105
- name: 'test',
106
- },
107
- } as const)
108
-
109
- const field = new FieldApi({
110
- form,
111
- name: 'name',
112
- validators: {
113
- onChangeAsync: async ({ value }) => {
114
- assertType<'test'>(value)
115
-
116
- return undefined
117
- },
118
- },
119
- })
120
- })
121
-
122
- it('should type an array sub-field properly', () => {
123
- type Person = {
124
- name: string
125
- age: number
126
- }
127
-
128
- const form = new FormApi({
129
- defaultValues: {
130
- nested: {
131
- people: [] as Person[],
132
- },
133
- },
134
- } as const)
135
-
136
- const field = new FieldApi({
137
- form,
138
- name: `nested.people[${1}].name`,
139
- validators: {
140
- onChangeAsync: async ({ value }) => {
141
- assertType<string>(value)
142
-
143
- return undefined
144
- },
145
- },
146
- })
147
-
148
- assertType<string>(field.state.value)
149
- })