Open History to see the last commit
1import type {
2 DeepKeys,
3 DeepKeysWhereValueIncludes,
4 DeepValue,
5 FieldApi,
6 FieldApiOptions,
7 FieldValidators,
8 FormErrorTypes,
9 FormGroupApi,
10 FormGroupOptions,
11 FormGroupState,
12 FormGroupValidators,
13 FormState,
14 ToFieldError,
15 ToFormGroupErrorTypes,
16} from '@tanstack/form-core'
17import type { Accessor, Component, JSX } from 'solid-js'
18β
19type ExactFieldBrand<out TValue> = {
20 readonly __tanstackFieldExactType: TValue
21}
22β
23type AcceptsFieldBrand<out TAcceptedValue> = {
24 readonly __tanstackFieldAcceptsType: TAcceptedValue
25}
26β
27type CompatibleFieldKey<TKey, TComponent, TTargetValue> =
28 TComponent extends ExactFieldBrand<infer TExact>
29 ? [TExact] extends [TTargetValue]
30 ? [TTargetValue] extends [TExact]
31 ? TKey
32 : never
33 : never
34 : TComponent extends AcceptsFieldBrand<infer TLoose>
35 ? [TTargetValue] extends [TLoose]
36 ? TKey
37 : never
38 : TKey
39β
40type FilteredFieldComponents<
41 TFieldComponents extends Record<string, Component<any>>,
42 TTargetValue,
43> = {
44 [
45 K in keyof TFieldComponents as CompatibleFieldKey<
46 K,
47 TFieldComponents[K],
48 TTargetValue
49 >
50 ]: TFieldComponents[K]
51}
52β
53type FieldComponentsMatchingType<
54 TFieldComponents extends Record<string, Component<any>>,
55 TTargetValue,
56> = unknown extends TTargetValue
57 ? TFieldComponents
58 : string extends keyof TFieldComponents
59 ? TFieldComponents
60 : FilteredFieldComponents<TFieldComponents, TTargetValue>
61β
62export type SolidFieldApi<
63 TFieldName,
64 TFieldValue,
65 TFieldError,
66 TFormData,
67 TFormErrorTypes extends FormErrorTypes,
68 TFieldComponents extends Record<string, Component<any>>,
69> = Accessor<
70 FieldApi<TFieldName, TFieldValue, TFieldError, TFormData, TFormErrorTypes>
71> &
72 FieldComponentsMatchingType<TFieldComponents, TFieldValue>
73β
74interface SolidSubscribeProps<TSourceData, TSelected> {
75 selector: (state: TSourceData) => TSelected
76 when?: (selected: NoInfer<TSelected>) => boolean
77 children: ((state: Accessor<NoInfer<TSelected>>) => JSX.Element) | JSX.Element
78}
79β
80export type SolidFormSubscribeProps<
81 TFormData,
82 TFormErrorTypes extends FormErrorTypes,
83 TSelected,
84> = SolidSubscribeProps<FormState<TFormData, TFormErrorTypes>, TSelected>
85β
86export type SolidFormSubscribeComponent<
87 TFormData,
88 TFormErrorTypes extends FormErrorTypes,
89> = <const TSelected>(
90 props: SolidFormSubscribeProps<TFormData, TFormErrorTypes, TSelected>,
91) => JSX.Element
92β
93export interface SolidFormFieldProps<
94 TFieldData,
95 TFieldName,
96 TFieldValue,
97 TFieldValidators extends FieldValidators<TFieldData, TFieldName, TFieldValue>,
98 TGroupFieldError,
99 TFormData,
100 TFormErrorTypes extends FormErrorTypes,
101 TFieldComponents extends Record<string, Component<any>>,
102> extends FieldApiOptions<
103 TFieldData,
104 TFieldName,
105 TFieldValue,
106 TFieldValidators,
107 TGroupFieldError,
108 TFormData,
109 TFormErrorTypes
110> {
111 children: (
112 fieldApi: SolidFieldApi<
113 TFieldName,
114 TFieldValue,
115 ToFieldError<
116 NoInfer<TFieldValidators>,
117 TGroupFieldError,
118 TFormErrorTypes
119 >,
120 TFormData,
121 TFormErrorTypes,
122 TFieldComponents
123 >,
124 ) => JSX.Element
125}
126β
127export interface SolidFormArrayFieldProps<
128 TFormData,
129 TFieldName,
130 TFieldValue,
131 TFieldValidators extends FieldValidators<TFormData, TFieldName, TFieldValue>,
132 TFormErrorTypes extends FormErrorTypes,
133> extends SolidFormFieldProps<
134 TFormData,
135 TFieldName,
136 TFieldValue,
137 TFieldValidators,
138 never,
139 TFormData,
140 TFormErrorTypes,
141 Record<never, never>
142> {}
143β
144export interface SolidFormFieldComponent<
145 TFormData,
146 TFormErrorTypes extends FormErrorTypes,
147 TFieldComponents extends Record<string, Component<any>>,
148> {
149 <
150 TFieldName extends DeepKeys<TFormData>,
151 const TFieldValidators extends FieldValidators<
152 TFormData,
153 TFieldName,
154 DeepValue<TFormData, TFieldName>
155 >,
156 >(
157 props: SolidFormFieldProps<
158 TFormData,
159 TFieldName,
160 DeepValue<TFormData, TFieldName>,
161 TFieldValidators,
162 never,
163 TFormData,
164 TFormErrorTypes,
165 TFieldComponents
166 >,
167 ): JSX.Element
168}
169β
170export interface SolidFormArrayFieldComponent<
171 TFormData,
172 TFormErrorTypes extends FormErrorTypes,
173 TFieldComponents extends Record<string, Component<any>>,
174> {
175 <
176 TFieldName extends DeepKeysWhereValueIncludes<TFormData, Array<any>>,
177 const TFieldValidators extends FieldValidators<
178 TFormData,
179 TFieldName,
180 DeepValue<TFormData, TFieldName>
181 >,
182 >(
183 props: SolidFormFieldProps<
184 TFormData,
185 TFieldName,
186 DeepValue<TFormData, TFieldName>,
187 TFieldValidators,
188 never,
189 TFormData,
190 TFormErrorTypes,
191 TFieldComponents
192 >,
193 ): JSX.Element
194}
195β
196export type SolidFormGroupSubscribeProps<
197 TGroupValue,
198 TGroupErrorTypes extends FormErrorTypes,
199 TSelected,
200> = SolidSubscribeProps<
201 FormGroupState<TGroupValue, TGroupErrorTypes>,
202 TSelected
203>
204β
205export type SolidFormGroupSubscribeComponent<
206 TGroupValue,
207 TGroupErrorTypes extends FormErrorTypes,
208> = <const TSelected>(
209 props: SolidFormGroupSubscribeProps<TGroupValue, TGroupErrorTypes, TSelected>,
210) => JSX.Element
211β
212export interface SolidFormGroupFieldComponent<
213 TFormData,
214 TGroupValue,
215 TGroupErrorTypes extends FormErrorTypes,
216 TFormErrorTypes extends FormErrorTypes,
217 TFieldComponents extends Record<string, Component<any>>,
218> {
219 <
220 TFieldName extends DeepKeys<TGroupValue>,
221 const TFieldValidators extends FieldValidators<
222 TGroupValue,
223 TFieldName,
224 DeepValue<TGroupValue, TFieldName>
225 >,
226 >(
227 props: SolidFormFieldProps<
228 TGroupValue,
229 TFieldName,
230 DeepValue<TGroupValue, TFieldName>,
231 TFieldValidators,
232 TGroupErrorTypes['fieldError'],
233 TFormData,
234 TFormErrorTypes,
235 TFieldComponents
236 >,
237 ): JSX.Element
238}
239β
240export interface SolidFormGroupArrayFieldComponent<
241 TFormData,
242 TGroupValue,
243 TGroupErrorTypes extends FormErrorTypes,
244 TFormErrorTypes extends FormErrorTypes,
245 TFieldComponents extends Record<string, Component<any>>,
246> {
247 <
248 TFieldName extends DeepKeysWhereValueIncludes<TGroupValue, Array<any>>,
249 const TFieldValidators extends FieldValidators<
250 TGroupValue,
251 TFieldName,
252 DeepValue<TGroupValue, TFieldName>
253 >,
254 >(
255 props: SolidFormFieldProps<
256 TGroupValue,
257 TFieldName,
258 DeepValue<TGroupValue, TFieldName>,
259 TFieldValidators,
260 TGroupErrorTypes['fieldError'],
261 TFormData,
262 TFormErrorTypes,
263 TFieldComponents
264 >,
265 ): JSX.Element
266}
267β
268export interface SolidFormGroupApi<
269 TFormData,
270 TGroupName,
271 TGroupValue,
272 TGroupErrorTypes extends FormErrorTypes,
273 TFormErrorTypes extends FormErrorTypes,
274 TFieldComponents extends Record<string, Component<any>>,
275> extends FormGroupApi<
276 TFormData,
277 TGroupName,
278 TGroupValue,
279 TGroupErrorTypes,
280 TFormErrorTypes
281> {
282 Field: SolidFormGroupFieldComponent<
283 TFormData,
284 TGroupValue,
285 TGroupErrorTypes,
286 TFormErrorTypes,
287 TFieldComponents
288 >
289 ArrayField: SolidFormGroupArrayFieldComponent<
290 TFormData,
291 TGroupValue,
292 TGroupErrorTypes,
293 TFormErrorTypes,
294 TFieldComponents
295 >
296 Subscribe: SolidFormGroupSubscribeComponent<TGroupValue, TGroupErrorTypes>
297}
298β
299export type SolidFormGroupAccessor<
300 TFormData,
301 TGroupName,
302 TGroupValue,
303 TGroupErrorTypes extends FormErrorTypes,
304 TFormErrorTypes extends FormErrorTypes,
305 TFieldComponents extends Record<string, Component<any>>,
306> = Accessor<
307 SolidFormGroupApi<
308 TFormData,
309 TGroupName,
310 TGroupValue,
311 TGroupErrorTypes,
312 TFormErrorTypes,
313 TFieldComponents
314 >
315> &
316 Pick<
317 SolidFormGroupApi<
318 TFormData,
319 TGroupName,
320 TGroupValue,
321 TGroupErrorTypes,
322 TFormErrorTypes,
323 TFieldComponents
324 >,
325 'Field' | 'ArrayField' | 'Subscribe'
326 >
327β
328export interface SolidFormGroupProps<
329 TFormData,
330 TGroupName,
331 TGroupValue,
332 TGroupValidators extends FormGroupValidators<TGroupValue>,
333 TFormErrorTypes extends FormErrorTypes,
334 TFieldComponents extends Record<string, Component<any>>,
335> extends Omit<
336 FormGroupOptions<
337 TFormData,
338 TGroupName,
339 TGroupValue,
340 TGroupValidators,
341 TFormErrorTypes
342 >,
343 'form'
344> {
345 children: (
346 groupApi: SolidFormGroupAccessor<
347 TFormData,
348 TGroupName,
349 TGroupValue,
350 ToFormGroupErrorTypes<NoInfer<TGroupValidators>>,
351 TFormErrorTypes,
352 TFieldComponents
353 >,
354 ) => JSX.Element
355}
356β
357export interface SolidFormGroupComponent<
358 TFormData,
359 TFormErrorTypes extends FormErrorTypes,
360 TFieldComponents extends Record<string, Component<any>>,
361> {
362 <
363 TGroupName extends DeepKeys<TFormData>,
364 TGroupValue extends DeepValue<TFormData, TGroupName>,
365 const TGroupValidators extends FormGroupValidators<TGroupValue>,
366 >(
367 props: SolidFormGroupProps<
368 TFormData,
369 TGroupName,
370 TGroupValue,
371 TGroupValidators,
372 TFormErrorTypes,
373 TFieldComponents
374 >,
375 ): JSX.Element
376}
377β
378export interface SolidTanStackFormComponents<
379 TFormData,
380 TFormErrorTypes extends FormErrorTypes,
381 TFieldComponents extends Record<string, Component<any>> = Record<
382 never,
383 never
384 >,
385> {
386 Field: SolidFormFieldComponent<TFormData, TFormErrorTypes, TFieldComponents>
387 ArrayField: SolidFormArrayFieldComponent<
388 TFormData,
389 TFormErrorTypes,
390 TFieldComponents
391 >
392 Subscribe: SolidFormSubscribeComponent<TFormData, TFormErrorTypes>
393 FormGroup: SolidFormGroupComponent<
394 TFormData,
395 TFormErrorTypes,
396 TFieldComponents
397 >
398}