'Error: Type 'number' is not assignable to type 'Decimal'

I want to manually create an object of my Prisma schema

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
}

But it throws an error

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

How to convert javascript number to Prisma Decimal type?



Solution 1:[1]

I was able to fix this error by using Prisma.Decimal class

Example

import { Prisma } from '@prisma/client'

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

See Working with Decimal documentation of Prisma

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roman Mahotskyi