I'm currently working on mapping a schema key to a different name in my database
interface Country {
isoCode: string,
nameEn: string,
nameDe: string,
phone: string,
bla: string
}
const CountryJson = {
isoCode: 'DE',
nameEn: 'Germany',
nameDe: 'Deutschland',
phone: '+49',
blubb: 'test123'
}
const testZodObj: toZod<Country> = z.object({
isoCode: z.string(),
nameEn: z.string(),
nameDe: z.string(),
phone: z.string(),
blubb: z.string(),
}).transform((item)=>{
const {blubb: bla, ...rest} = item
return {
...rest,
bla
}
})
type countryArray = z.infer<typeof testZodObj>
function print(): countryArray{
return testZodObj.parse(CountryJson)
}
const out = print()
console.log(out)
However, the transform function returns a ZodType, causing testZodObj to now expect a ZodEffects. Do you have any suggestions on how I could make the key names match the interface?
blubb
is the value retrieved from the API and bla
is the value I want to store it as.