Error: Type 'number' is not assignable to type 'Decimal'
Error: Type 'number' is not assignable to type 'Decimal'
我想手动创建 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
class
修复此错误
例子
import { Prisma } from '@prisma/client'
const order: Order = {
id: '1',
name: 'Name',
price: new Prisma.Decimal(99)
}
请参阅 Working with Decimal Prisma 文档
我想手动创建 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
class
例子
import { Prisma } from '@prisma/client'
const order: Order = {
id: '1',
name: 'Name',
price: new Prisma.Decimal(99)
}
请参阅 Working with Decimal Prisma 文档