You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)
"react": "^19.0.0",
"zod": "^3.24.1"
What steps can reproduce the bug?
create the Zod schema of the task object with pluginZod
look into the taskSchema.ts
the typescript compiler will return an error on props which are an object type (in this case: Date) or an enum type (primitive types, e.g. task.id works as usual)
How often does this bug happen?
Every time
What is the expected behavior?
No compiler errors in zod schemas.
Additional information
These are the ts files generated by pluginTs:
Task.ts:
import type { Instant } from './Instant.ts'
import type { TaskStatus } from './TaskStatus.ts'
export type Task = {
/**
* @type string
*/
readonly id: string
/**
* @type string | undefined, date-time
*/
beginTime?: Instant
/**
* @type string | undefined
*/
taskStatus?: TaskStatus
}
and these are the zod schemas generated by pluginZod:
taskStatusSchema.ts:
import { z } from 'zod'
export const taskStatusSchema = z.enum(['STARTED', 'STOPPED', 'PAUSED'])
instantSchema.ts:
import { z } from 'zod'
export const instantSchema = z.string().datetime({ offset: true })
taskSchema.ts:
import type { Task } from '../types/Task.ts'
import type { ToZod } from '@kubb/plugin-zod/utils'
import { instantSchema } from './instantSchema.ts'
import { taskStatusSchema } from './taskStatusSchema.ts'
import { z } from 'zod'
export const taskSchema = z.object({
id: z.string(),
beginTime: z.lazy(() => instantSchema).optional(),
taskStatus: z.lazy(() => taskStatusSchema).optional(),
} satisfies ToZod<Task>)
For taskSchema.beginTime, I get the following typescript compiler error:
Type 'ZodOptional<ZodLazy<ZodString>>' is not assignable to type 'ZodWithEffects<ZodOptional<ZodType<Date, ZodTypeDef, Date>>> | ZodWithEffects<ZodDefault<ZodType<Date, ZodTypeDef, Date>>>'.
Type 'ZodOptional<ZodLazy<ZodString>>' is not assignable to type 'ZodOptional<ZodType<Date, ZodTypeDef, Date>>'.
Type 'ZodLazy<ZodString>' is not assignable to type 'ZodType<Date, ZodTypeDef, Date>'.
Types of property '_type' are incompatible.
Type 'string' is not assignable to type 'Date'. [2322]
For taskSchema.taskStatus, I get the following typescript compiler error:
Type 'ZodOptional<ZodLazy<ZodEnum<["STARTED", "STOPPED", "PAUSED"]>>>' is not assignable to type 'ZodWithEffects<ZodOptional<ZodType<TaskStatus, ZodTypeDef, TaskStatus>>> | ZodWithEffects<ZodDefault<ZodType<TaskStatus, ZodTypeDef, TaskStatus>>>'.
Type 'ZodOptional<ZodLazy<ZodEnum<["STARTED", "STOPPED", "PAUSED"]>>>' is not assignable to type 'ZodOptional<ZodType<TaskStatus, ZodTypeDef, TaskStatus>> | ZodEffects<ZodOptional<ZodType<TaskStatus, ZodTypeDef, TaskStatus>>, any, any> | ZodEffects<...>'.
Type 'ZodOptional<ZodLazy<ZodEnum<["STARTED", "STOPPED", "PAUSED"]>>>' is not assignable to type 'ZodOptional<ZodType<TaskStatus, ZodTypeDef, TaskStatus>>'.
Type 'ZodLazy<ZodEnum<["STARTED", "STOPPED", "PAUSED"]>>' is not assignable to type 'ZodType<TaskStatus, ZodTypeDef, TaskStatus>'.
Types of property '_type' are incompatible.
Type '"STARTED" | "STOPPED" | "PAUSED"' is not assignable to type 'TaskStatus'.
Type '"STARTED"' is not assignable to type 'TaskStatus'. [2322]
The text was updated successfully, but these errors were encountered:
When you use typed: true,, Kubb will add satisfies ToZod<TYPE>. But if dateType for pluginTs is different from the one in pluginZod, then TypeScript will complain. We could make it as a cast but that will probably give another type then it should be. Could you try by using the samedateType?
But if dateType for pluginTs is different from the one in pluginZod,
Yes, for the dateTime-issue it works. I changed it to:
pluginTs({
dateType: 'string'
..
})
pluginZod({
dateType: 'stringOffset' // stringOffset is also string
..
})
The taskSchema.beginTime property no longer causes a Typescript compiler error. I wonder if it would make sense to support Date() (and not just strings) for pluginZod.dateType:
pluginTs({
dateType: 'date'
..
})
pluginZod({
// Currently not possible - Are there any disadvantages to be expected?
dateType: 'date'
..
})
What version of
kubb
is running?3.3.3
What kind of platform do you use?
MacOS
How does your
kubb.config.ts
config look likeSwagger/OpenAPI file?
What version of external packages are you using(
@tanstack-query
,MSW
,React
,Vue
, ...)"react": "^19.0.0",
"zod": "^3.24.1"
What steps can reproduce the bug?
pluginZod
taskSchema.ts
object
type (in this case:Date
) or anenum
type (primitive types, e.g.task.id
works as usual)How often does this bug happen?
Every time
What is the expected behavior?
No compiler errors in zod schemas.
Additional information
These are the
ts
files generated bypluginTs
:Task.ts
:TaskStatus.ts
:Instant.ts
:and these are the zod schemas generated by
pluginZod
:taskStatusSchema.ts
:instantSchema.ts
:taskSchema.ts
:For
taskSchema.beginTime
, I get the following typescript compiler error:For
taskSchema.taskStatus
, I get the following typescript compiler error:The text was updated successfully, but these errors were encountered: