fix: type checking issues for recursive types

This commit is contained in:
Andrew Bastin
2023-12-13 03:01:01 +05:30
parent b07d0c69cc
commit 9e7f1b58b9
4 changed files with 16 additions and 10 deletions

View File

@@ -18,12 +18,15 @@ const baseCollectionSchema = z.object({
), ),
}) })
type Collection = z.infer<typeof baseCollectionSchema> & { type Input = z.input<typeof baseCollectionSchema> & {
folders: Collection[] folders: Input[]
} }
//@ts-expect-error ~ Recursive type type Output = z.output<typeof baseCollectionSchema> & {
export const V1_SCHEMA: z.ZodType<Collection> = baseCollectionSchema.extend({ folders: Output[]
}
export const V1_SCHEMA: z.ZodType<Output, z.ZodTypeDef, Input> = baseCollectionSchema.extend({
folders: z.lazy(() => z.array(V1_SCHEMA)), folders: z.lazy(() => z.array(V1_SCHEMA)),
}) })

View File

@@ -23,12 +23,15 @@ const baseCollectionSchema = z.object({
headers: z.union([HoppRESTHeaders, z.array(GQLHeader)]), headers: z.union([HoppRESTHeaders, z.array(GQLHeader)]),
}) })
type Collection = z.infer<typeof baseCollectionSchema> & { type Input = z.input<typeof baseCollectionSchema> & {
folders: Collection[] folders: Input[]
} }
// @ts-expect-error ~ Recursive type type Output = z.output<typeof baseCollectionSchema> & {
export const V2_SCHEMA: z.ZodType<Collection> = baseCollectionSchema.extend({ folders: Output[]
}
export const V2_SCHEMA: z.ZodType<Output, z.ZodTypeDef, Input> = baseCollectionSchema.extend({
folders: z.lazy(() => z.array(V2_SCHEMA)), folders: z.lazy(() => z.array(V2_SCHEMA)),
}) })

View File

@@ -13,5 +13,5 @@
"emitDeclarationOnly": true, "emitDeclarationOnly": true,
"declarationDir": "./dist" "declarationDir": "./dist"
}, },
"include": ["src/*.ts"] "include": ["src/**/*.ts"]
} }

View File

@@ -10,5 +10,5 @@
"skipLibCheck": true, "skipLibCheck": true,
"resolveJsonModule": true "resolveJsonModule": true
}, },
"include": ["src/*.ts"] "include": ["src/**/*.ts"]
} }