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> & {
folders: Collection[]
type Input = z.input<typeof baseCollectionSchema> & {
folders: Input[]
}
//@ts-expect-error ~ Recursive type
export const V1_SCHEMA: z.ZodType<Collection> = baseCollectionSchema.extend({
type Output = z.output<typeof baseCollectionSchema> & {
folders: Output[]
}
export const V1_SCHEMA: z.ZodType<Output, z.ZodTypeDef, Input> = baseCollectionSchema.extend({
folders: z.lazy(() => z.array(V1_SCHEMA)),
})

View File

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

View File

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

View File

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