gpt4 book ai didi

prisma - 错误 : Type 'number' is not assignable to type 'Decimal'

转载 作者:行者123 更新时间:2023-12-05 01:23:43 54 4
gpt4 key购买 nike

我想手动创建我的 Prisma 模式的对象

const order: Order = {
id: '1',
name: 'Name',
price: 99
}

...

// Somewhere in autogenerated file by Prisma
export type Order = {
id: string
name: string
price: Prisma.Decimal
}

但是会报错

Type 'number' is not assignable to type 'Decimal'.

如何将 javascript number 转换为 Prisma Decimal 类型?

最佳答案

我能够使用 Prisma.Decimal 类修复此错误

例子

import { Prisma } from '@prisma/client'

const order: Order = {
id: '1',
name: 'Name',
price: new Prisma.Decimal(99)
}

参见 Working with Decimal Prisma 文档

关于prisma - 错误 : Type 'number' is not assignable to type 'Decimal' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71942079/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com