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

index.ts

33 lines1.1 KB

1import { errorsHidden } from './errorsHidden'
2import { schemaErrorOnUnmountedField } from './schemaErrorOnUnmountedField'
3import { serverErrorOnUnmountedField } from './serverErrorOnUnmountedField'
4import type { FieldErrorDebugCase, FieldErrorDebugCaseContext } from './types'
5import type { FieldErrorDebugSuspicion } from '../../../eventClientTypes'
6​
7export type { FieldErrorDebugCase } from './types'
8​
9/**
10 * The order of these cases is important.
11 * They are evaluated in order, and the first one that matches will be used.
12 *
13 * The most specific cases should be first.
14 */
15const fieldErrorDebugCases = [
16 schemaErrorOnUnmountedField,
17 serverErrorOnUnmountedField,
18 errorsHidden,
19] satisfies ReadonlyArray<FieldErrorDebugCase>
20​
21export function getFieldErrorDebugSuspicions(
22 context: FieldErrorDebugCaseContext,
23 cases: ReadonlyArray<FieldErrorDebugCase> = fieldErrorDebugCases,
24): Array<FieldErrorDebugSuspicion> {
25 const suspicions: Array<FieldErrorDebugSuspicion> = []
26​
27 for (const debugCase of cases) {
28 const suspicion = debugCase.evaluate(context)
29 if (suspicion) suspicions.push(suspicion)
30 }
31​
32 return suspicions