From 755361681cea12a511843c2c6e1c3a00234c1e65 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Tue, 4 Oct 2022 09:12:05 +0100 Subject: [PATCH] Add explanation comment around the schema type and whay we need to remove the optional def for the schema Signed-off-by: Harry Hogg --- plugins/permission-node/src/types.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/permission-node/src/types.ts b/plugins/permission-node/src/types.ts index 8725316de0..521c8ac3ad 100644 --- a/plugins/permission-node/src/types.ts +++ b/plugins/permission-node/src/types.ts @@ -55,6 +55,10 @@ export type PermissionRule< * A ZodSchema that documents the parameters that this rule accepts. */ schema: z.ZodObject<{ + // Parameters can be optional, however we we want to make sure that the + // parameters are always present in the schema, even if they are undefined. + // We remove the optional flag from the schema, and then add it back in + // with an optional zod type. [P in keyof TParams]-?: TParams[P] extends undefined ? z.ZodOptionalType> : z.ZodType;