Skip to content

Commit d1f6df8

Browse files
Siyasangatumbledwyer
authored andcommitted
fix: remove .shape from ActionConfig extends to properly override conditionals
The .extend(z.object({...}).shape) pattern was preventing proper field overrides. Specifically, ReadActionConfig's conditionals: z.never() override wasn't working, causing validation errors when READ actions inherited the array conditionals from ActionConfigBase. This fixes Zod validation errors: - 'expected never, received array' for READ action conditionals - Proper discriminated union validation for all action types
1 parent bed09af commit d1f6df8

File tree

1 file changed

+35
-48
lines changed

1 file changed

+35
-48
lines changed

packages/commons/src/events/ActionConfig.ts

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -53,59 +53,45 @@ const DeclarationActionBase = ActionConfigBase.extend({
5353
deduplication: DeduplicationConfig.optional()
5454
})
5555

56-
const ReadActionConfig = ActionConfigBase.extend(
57-
z.object({
58-
type: z.literal(ActionType.READ),
59-
review: DeclarationReviewConfig.describe(
60-
'Configuration of the review page for read-only view.'
61-
),
62-
conditionals: z
63-
.never()
64-
.optional()
65-
.describe('Read-action can not be disabled or hidden with conditionals.')
66-
}).shape
67-
)
56+
const ReadActionConfig = ActionConfigBase.extend({
57+
type: z.literal(ActionType.READ),
58+
review: DeclarationReviewConfig.describe(
59+
'Configuration of the review page for read-only view.'
60+
),
61+
conditionals: z
62+
.never()
63+
.optional()
64+
.describe('Read-action can not be disabled or hidden with conditionals.')
65+
})
6866

69-
const DeclareConfig = DeclarationActionBase.extend(
70-
z.object({
71-
type: z.literal(ActionType.DECLARE),
72-
review: DeclarationReviewConfig.describe(
73-
'Configuration of the review page fields.'
74-
)
75-
}).shape
76-
)
67+
const DeclareConfig = DeclarationActionBase.extend({
68+
type: z.literal(ActionType.DECLARE),
69+
review: DeclarationReviewConfig.describe(
70+
'Configuration of the review page fields.'
71+
)
72+
})
7773

78-
const RejectConfig = ActionConfigBase.extend(
79-
z.object({
80-
type: z.literal(ActionType.REJECT)
81-
}).shape
82-
)
74+
const RejectConfig = ActionConfigBase.extend({
75+
type: z.literal(ActionType.REJECT)
76+
})
8377

84-
const ValidateConfig = DeclarationActionBase.extend(
85-
z.object({
86-
type: z.literal(ActionType.VALIDATE)
87-
}).shape
88-
)
78+
const ValidateConfig = DeclarationActionBase.extend({
79+
type: z.literal(ActionType.VALIDATE)
80+
})
8981

90-
const RegisterConfig = DeclarationActionBase.extend(
91-
z.object({
92-
type: z.literal(ActionType.REGISTER)
93-
}).shape
94-
)
82+
const RegisterConfig = DeclarationActionBase.extend({
83+
type: z.literal(ActionType.REGISTER)
84+
})
9585

96-
const PrintCertificateActionConfig = ActionConfigBase.extend(
97-
z.object({
98-
type: z.literal(ActionType.PRINT_CERTIFICATE),
99-
printForm: ActionFormConfig
100-
}).shape
101-
)
86+
const PrintCertificateActionConfig = ActionConfigBase.extend({
87+
type: z.literal(ActionType.PRINT_CERTIFICATE),
88+
printForm: ActionFormConfig
89+
})
10290

103-
const RequestCorrectionConfig = ActionConfigBase.extend(
104-
z.object({
105-
type: z.literal(ActionType.REQUEST_CORRECTION),
106-
correctionForm: ActionFormConfig
107-
}).shape
108-
)
91+
const RequestCorrectionConfig = ActionConfigBase.extend({
92+
type: z.literal(ActionType.REQUEST_CORRECTION),
93+
correctionForm: ActionFormConfig
94+
})
10995

11096
const CustomActionConfig = ActionConfigBase.merge(
11197
z.object({
@@ -149,7 +135,8 @@ export type ActionConfig = z.infer<typeof ActionConfig>
149135

150136
// Build a runtime set directly from the schema
151137
export const actionConfigTypes: Set<ActionConfigTypes> = new Set(
152-
ActionConfig.options.map((opt) => opt.shape.type.value)
138+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
139+
ActionConfig.options.map((opt: z.ZodObject<any>) => opt.shape.type.value)
153140
)
154141
/**
155142
* Action types that come specifically from the country configuration.

0 commit comments

Comments
 (0)