Skip to content

Commit 4160d1c

Browse files
remcohaszingkvz
andauthored
Fix deep types error (#227)
* Fix deep types error One of the big features of TypeScript, is that it can infer types based on context. This is powerful, but it comes at a cost. Determining types based on inference consumes much more resources than using a type annotation. This is an important reason to add explicit type annotations. We heavily rely on Zod though. Zod is powerful, but it heavily relies on inference. This means that by using Zod, we sacrifice type checking performance. Zod 4 will supposedly be more performant. This is great, but by definition it can’t be as performant as regular types. When the types become really complex, TypeScript may error on this. An explicit type annotation in the right spot fixes this. This PR uses this to resolve the type error. I can’t explain why this surfaced here, but not in our internal repos these schemas originate from. * Update src/alphalib/types/template.ts --------- Co-authored-by: Kevin van Zonneveld <vanzonneveld@gmail.com>
1 parent be42cc1 commit 4160d1c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/alphalib/types/template.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type StepInput = z.input<typeof stepSchema>
1515
export type StepInputWithUse = StepInput & RobotUse
1616
export type Steps = z.infer<typeof stepsSchema>
1717
export type StepsInput = z.input<typeof stepsSchema>
18+
const optionalStepsSchema = stepsSchema.optional()
1819

1920
export const stepSchemaWithHiddenFields = z
2021
.object({
@@ -63,7 +64,8 @@ export const assemblyInstructionsSchema = z.object({
6364
.describe(
6465
'Set this to true to reduce the response from an Assembly POST request to only the necessary fields. This prevents any potentially confidential information being leaked to the end user who is making the Assembly request. A successful Assembly will only include the ok and assembly_id fields. An erroneous Assembly will only include the error, http_code, message and assembly_id fields. The full Assembly Status will then still be sent to the notify_url if one was specified.',
6566
),
66-
steps: stepsSchema.optional(),
67+
// This is done to avoid heavy inference cost
68+
steps: optionalStepsSchema as typeof optionalStepsSchema,
6769
template_id: z.string().optional().describe('The Template ID to use'),
6870
})
6971

0 commit comments

Comments
 (0)