Add explanation comment around the schema type and whay we need to remove the optional def for the schema

Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
Harry Hogg
2022-10-04 09:12:05 +01:00
parent 1d4b847c98
commit 755361681c
+4
View File
@@ -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<TParams[P]>>
: z.ZodType<TParams[P], any, any>;