From ad647b5d275d0ca485e2ce0940fc0757fe8521aa Mon Sep 17 00:00:00 2001 From: Patrick Hein Date: Thu, 6 May 2021 02:11:28 +0200 Subject: [PATCH] allows optional enums (#694) --- src/utils.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index ff587244..0c1706a3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -203,7 +203,9 @@ export type Assign = Simplify> * A schema for enum structs. */ -export type EnumSchema = { [K in T]: K } +export type EnumSchema = { + [K in NonNullable]: K +} /** * Check if a type is an exact match. @@ -307,14 +309,14 @@ export type If = B extends true ? Then : Else * A schema for any type of struct. */ -export type StructSchema = [T] extends [string] - ? [T] extends [IsMatch] +export type StructSchema = [T] extends [string | undefined] + ? [T] extends [IsMatch] ? null : [T] extends [IsUnion] ? EnumSchema : T - : [T] extends [number] - ? [T] extends [IsMatch] + : [T] extends [number | undefined] + ? [T] extends [IsMatch] ? null : [T] extends [IsUnion] ? EnumSchema