Skip to content

Commit

Permalink
Use preprocess instead of transform. Fix loss of types from preproces…
Browse files Browse the repository at this point in the history
…sNulls returning any instead of schema type.
  • Loading branch information
JasonLin0991 committed Jun 25, 2024
1 parent aa55c21 commit 40bea78
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ZodSchema } from 'zod'
import { z } from 'zod'
import {
actuaryCommunicationTypeSchema,
Expand All @@ -14,6 +13,7 @@ import {
} from '../../../../app-web/src/common-code/proto/healthPlanFormDataProto/zodSchemas'
import { statusSchema } from './statusType'
import type { ZodEffects } from 'zod/lib/types'
import type { RawCreateParams, ZodTypeAny } from 'zod/lib/types'

const documentSchema = z.object({
name: z.string(),
Expand All @@ -36,8 +36,11 @@ const packagesWithSharedRateCerts = z.object({
packageStatus: statusSchema.optional(),
})

function preprocessNulls<T extends ZodSchema>(schema: T): ZodEffects<T> {
return z.preprocess((val) => val ?? undefined, schema)
function preprocessNulls<T extends ZodTypeAny>(
schema: T,
params?: RawCreateParams
): ZodEffects<T, T['_output'], unknown> {
return z.preprocess((val) => val ?? undefined, schema, params)
}

const contractFormDataSchema = z.object({
Expand Down

0 comments on commit 40bea78

Please sign in to comment.