Skip to content

Commit aba2ce7

Browse files
committed
feat: typos
1 parent 6f455c5 commit aba2ce7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/components/forms/public/response-schema.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@
99
import { z } from 'zod';
1010

1111
import { FormField } from '@/core/domain/entities/form';
12+
import { AnswerValue } from '@/core/domain/entities/response';
1213
import { FIELD_TYPES } from '@/core/domain/value-objects/field-types';
1314

15+
/** Zod schema types that can be produced for a single form field (string, number | null, string[]) */
16+
export type FieldSchema =
17+
| z.ZodType<string>
18+
| z.ZodType<number | null>
19+
| z.ZodType<string[]>;
20+
1421
/**
1522
* Builds a Zod schema dynamically from form fields.
1623
* Each field ID becomes a key in the resulting object schema.
1724
*/
18-
export const buildResponseSchema = (fields: FormField[]) => {
19-
const shape: Record<string, z.ZodTypeAny> = {};
25+
export const buildResponseSchema = (
26+
fields: FormField[],
27+
): z.ZodType<Record<string, AnswerValue>> => {
28+
const shape: Record<string, FieldSchema> = {};
2029

2130
for (const field of fields) {
2231
shape[field.id] = buildFieldSchema(field);
@@ -26,7 +35,7 @@ export const buildResponseSchema = (fields: FormField[]) => {
2635
};
2736

2837
/** Builds the Zod schema for a single field based on its type and configuration */
29-
export const buildFieldSchema = (field: FormField): z.ZodTypeAny => {
38+
export const buildFieldSchema = (field: FormField): FieldSchema => {
3039
switch (field.type) {
3140
case FIELD_TYPES.SHORT_TEXT:
3241
case FIELD_TYPES.LONG_TEXT:
@@ -60,7 +69,9 @@ export const buildFieldSchema = (field: FormField): z.ZodTypeAny => {
6069
? z.array(z.string()).min(1, 'Selecciona al menos una opción')
6170
: z.array(z.string());
6271

63-
default:
64-
return z.unknown();
72+
default: {
73+
const exhaustive: never = field.type;
74+
throw new Error(`Unhandled field type: ${exhaustive}`);
75+
}
6576
}
6677
};

0 commit comments

Comments
 (0)