簡體   English   中英

由於類型不正確,Prisma 更新功能失敗

[英]Prisma update function fails because of incorrect type

我正在使用 Prisma2。 突變函數如下所示:

const updateUserProfileDetails = async (
  inputValues, ctx: { session?: SessionContext } = {}
) => {
  const profile = await db.user.update({
    where: { id: ctx.session!.userId },
    data: {
      profile: {
        update: {
          aboutMe: "this is a random message for about me.",  // type error is displayed here
          location: "London, UK", // same type error here
          profession: "rubber duck", // same type error here
        },
      },
    },
  });
  return profile;
};

然而,關於aboutMelocationprofession道具,打字稿是尖叫:

Type 'string' is not assignable to type 'NullableStringFieldUpdateOperationsInput | undefined'.ts(2322)

相關的架構如下所示:

model User {
  id             Int       @default(autoincrement()) @id
  createdAt      DateTime  @default(now())
  updatedAt      DateTime  @updatedAt
  firstName      String?
  lastName       String?
  email          String    @unique
  hashedPassword String?
  role           String    @default("user")
  sessions       Session[]
  profile        Profile?
}

model Profile {
  id                 Int       @default(autoincrement()) @id
  aboutMe            String?
  location           String?
  profession         String?
  user               User      @relation(fields:[userId], references: [id])
  userId             Int
}

版本:

@prisma/cli: 2.6.0 => 2.6.0 
@prisma/client: 2.6.0 => 2.6.0 

我一直無法找到(在我搜索文件夾中) NullableStringFieldUpdateOperationsInput的定義。 我究竟做錯了什么?

你能將@prisma/cli@prisma/client2.7.1嗎? 它在最新版本中運行良好。 我已經試過了,TS 沒有在這里抱怨,而且查詢也能正常工作。

打字稿片段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM