zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

TRPC Plugin generated typescript errors #455

Closed mbrimmer83 closed 1 year ago

mbrimmer83 commented 1 year ago

Description and expected behavior After generating ZenStack with the TRPC plugin. Some of the schemas have typescript errors. I currently have 133 errors and they all appear to be similar in nature. I'm not ruling out an issue in my setup or library version issue.

Type 
  'ZodObject<{ 
      where: ZodLazy<ZodType<Omit<UserBadgeWhereUniqueInput, "zenstack_transaction" | "zenstack_guard">, ZodTypeDef, Omit<UserBadgeWhereUniqueInput, "zenstack_transaction" | "zenstack_guard">>>; 
      update: ZodUnion<...>; 
      create: ZodUnion<...>; 
    }, "strict", ZodTypeAny, { ...; }, { ...; }>'

is not assignable to type 

  'ZodType<Omit<UserBadgeUpsertWithWhereUniqueWithoutUserInput, "zenstack_transaction" | "zenstack_guard">, ZodTypeDef, Omit<...>>'.

The types of '_type.update' are incompatible between these types.
Type 
  '(Omit<UserBadgeUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard"> | 
    Omit<UserBadgeUncheckedUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard">) & 
    (Omit<...> | ... 1 more ... | undefined)'
is not assignable to type 
  '(Without<UserBadgeUpdateWithoutUserInput, UserBadgeUncheckedUpdateWithoutUserInput> & 
    UserBadgeUncheckedUpdateWithoutUserInput) | 
    (Without<...> & UserBadgeUpdateWithoutUserInput)'.
Type 
  'Omit<UserBadgeUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard"> & 
   Omit<UserBadgeUncheckedUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard">' 
is not assignable to type 
  '(Without<UserBadgeUpdateWithoutUserInput, UserBadgeUncheckedUpdateWithoutUserInput> & 
    UserBadgeUncheckedUpdateWithoutUserInput) | 
    (Without<...> & UserBadgeUpdateWithoutUserInput)'.
Type 
  'Omit<UserBadgeUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard"> & 
   Omit<UserBadgeUncheckedUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard">' 
is not assignable to type 
  'Without<UserBadgeUncheckedUpdateWithoutUserInput, UserBadgeUpdateWithoutUserInput> & 
   UserBadgeUpdateWithoutUserInput'.
Type 
  'Omit<UserBadgeUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard"> & 
   Omit<UserBadgeUncheckedUpdateWithoutUserInput, "zenstack_transaction" | "zenstack_guard">' 
is not assignable to type 
  'Without<UserBadgeUncheckedUpdateWithoutUserInput, UserBadgeUpdateWithoutUserInput>'.
Types of property 'badgeId' are incompatible.
Type 
  'string | StringFieldUpdateOperationsInput | undefined' 
is not assignable to type 
  'undefined'.
Type 'string' is not assignable to type 'undefined'.

Environment (please complete the following information):

Additional context

/* eslint-disable */
import { z } from 'zod'
import { UserBadgeWhereUniqueInputObjectSchema } from './UserBadgeWhereUniqueInput.schema'
import { UserBadgeUpdateWithoutUserInputObjectSchema } from './UserBadgeUpdateWithoutUserInput.schema'
import { UserBadgeUncheckedUpdateWithoutUserInputObjectSchema } from './UserBadgeUncheckedUpdateWithoutUserInput.schema'
import { UserBadgeCreateWithoutUserInputObjectSchema } from './UserBadgeCreateWithoutUserInput.schema'
import { UserBadgeUncheckedCreateWithoutUserInputObjectSchema } from './UserBadgeUncheckedCreateWithoutUserInput.schema'

import type { Prisma } from '@prisma/client'
// Schema has the error
const Schema: z.ZodType<
  Omit<
    Prisma.UserBadgeUpsertWithWhereUniqueWithoutUserInput,
    'zenstack_transaction' | 'zenstack_guard'
  >
> = z
  .object({
    where: z.lazy(() => UserBadgeWhereUniqueInputObjectSchema),
    update: z.union([
      z.lazy(() => UserBadgeUpdateWithoutUserInputObjectSchema),
      z.lazy(() => UserBadgeUncheckedUpdateWithoutUserInputObjectSchema)
    ]),
    create: z.union([
      z.lazy(() => UserBadgeCreateWithoutUserInputObjectSchema),
      z.lazy(() => UserBadgeUncheckedCreateWithoutUserInputObjectSchema)
    ])
  })
  .strict()

export const UserBadgeUpsertWithWhereUniqueWithoutUserInputObjectSchema = Schema
mbrimmer83 commented 1 year ago

Resolved by downgrading zod from v3.21.4 to v3.21.1

https://github.com/colinhacks/zod/issues/2184#issuecomment-1573154480

ymc9 commented 1 year ago

Keeping this issue open for adding a FAQ into documentation.

ymc9 commented 1 year ago

Closing since documentation is updated