diff --git a/packages/backend/toolchain/build/schema/serializer.ts b/packages/backend/toolchain/build/schema/serializer.ts index 5bde0e6e..4b8d4dff 100644 --- a/packages/backend/toolchain/build/schema/serializer.ts +++ b/packages/backend/toolchain/build/schema/serializer.ts @@ -105,14 +105,17 @@ function generateSerializableTypeSchema( if (type.isObject()) { const stringIndexType = type.getStringIndexType(); + + let indexTypes = []; + if (stringIndexType) { const indexType = generateSerializableTypeSchema(stringIndexType); - return s.record(indexType); + indexTypes.push(s.record(indexType)); } const numberIndexType = type.getNumberIndexType(); if (numberIndexType) { const indexType = generateSerializableTypeSchema(numberIndexType); - return s.record(indexType); + indexTypes.push(s.record(indexType)); } const properties = type.getProperties(); const propMap = properties.map((prop) => { @@ -122,7 +125,14 @@ function generateSerializableTypeSchema( type ? generateSerializableTypeSchema(type) : s.unknown(), ]; }); - return s.object(Object.fromEntries(propMap)); + + const objectSchema = s.object(Object.fromEntries(propMap)); + + if (indexTypes[0]) { + return s.intersection(objectSchema, indexTypes[0]); + } + + return objectSchema; } return s.unknown(); @@ -260,6 +270,8 @@ interface Array { [n: number]: T; } +type PropertyKey = string | number | symbol; + // We don't want to serialize Date from typescript // so we need to override the Date interface // to not be serialized, and instead be treated as a Date object