Skip to content

Commit c67fd9b

Browse files
committed
chore: typeguard for instrument validation schema
1 parent 7e3e1e1 commit c67fd9b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

apps/web/src/features/upload/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ type AnyZodTypeDef = z.ZodTypeDef & { typeName: ZodTypeName };
6262

6363
type AnyZodArrayDef = z.ZodArrayDef & { type: z.AnyZodObject };
6464

65+
function isZodObject(value: unknown): value is z.AnyZodObject {
66+
return isPlainObject(value);
67+
}
68+
6569
function isZodTypeDef(value: unknown): value is AnyZodTypeDef {
6670
return isPlainObject(value) && ZOD_TYPE_NAMES.includes(value.typeName as ZodTypeName);
6771
}
@@ -424,7 +428,11 @@ function generateSampleData({
424428
export function createUploadTemplateCSV(instrument: AnyUnilingualFormInstrument) {
425429
// TODO - type validationSchema as object
426430
try {
427-
const instrumentSchema = instrument.validationSchema as z.AnyZodObject;
431+
//This needs to be tested!!!
432+
if (!isZodObject(instrument.validationSchema)) {
433+
throw new Error('Error in validation schema type');
434+
}
435+
const instrumentSchema = instrument.validationSchema;
428436

429437
const instrumentSchemaDef: unknown = instrument.validationSchema._def;
430438

0 commit comments

Comments
 (0)