Prisma's Decimal is incompatible with decimal.js
See original GitHub issueBug description
Prisma client bundles decimal.js and exports the class Decimal. Unfortunately, that class cannot be used with the Decimal
class imported directly from decimal.js
, because both classes declare toStringTag
.
Example:
import { Decimal } from "decimal.js"
import { Prisma } from "@prisma/client"
const test = new Decimal(new Prisma.Decimal("12.0"))
// FYI: const test2 = new Prisma.Decimal(new Decimal("12.0")) also gives a type error
Gives the following error
Argument of type ‘Decimal’ is not assignable to parameter of type ‘Value’. Type ‘import(“*/node_modules/@prisma/client/runtime/index").Decimal’ is not assignable to type 'import("/node_modules/decimal.js/decimal”).default’. Types have separate declarations of a private property ‘toStringTag’.
How to reproduce
- Install decimal.js 10.4.2 and @prisma/client 4.6.1.
- The following gives a type error in typescript (tested with 4.8.4):
import { Decimal } from "decimal.js"
import { Prisma } from "@prisma/client"
const test = new Decimal(new Prisma.Decimal(12.0))
// FYI: const test2 = new Prisma.Decimal(new Decimal("12.0")) also gives a type error
Expected behavior
The Decimals from Prisma and decimal.js should be compatible.
This issue is particularly painful when working with mathjs (which depends on decimal.js). The BigNumber
type from mathjs (which is just reexported Decimal
from decimal.js
, is also incompatible with the Prisma’s Decimal
Environment & setup
- OS: macOS Ventura
- Database: PostgreSQL
- Node.js version: 16.14
Prisma information
model Order {
id Int @id @default(autoincrement())
amount Decimal
}
Prisma Version
prisma : 4.6.1
@prisma/client : 4.6.1
Current platform : darwin-arm64
Query Engine (Node-API) : libquery-engine 694eea289a8462c80264df36757e4fdc129b1b32 (at ../../node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine : migration-engine-cli 694eea289a8462c80264df36757e4fdc129b1b32 (at ../../node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine : introspection-core 694eea289a8462c80264df36757e4fdc129b1b32 (at ../../node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary : prisma-fmt 694eea289a8462c80264df36757e4fdc129b1b32 (at ../../node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm : @prisma/prisma-fmt-wasm 4.6.1-3.694eea289a8462c80264df36757e4fdc129b1b32
Default Engines Hash : 694eea289a8462c80264df36757e4fdc129b1b32
Studio : 0.476.0
Preview Features : interactiveTransactions, metrics
Issue Analytics
- State:
- Created 10 months ago
- Reactions:2
- Comments:6
Top GitHub Comments
Decimal.js 10.4.3 includes the PR removing toStringTag from the typescript type definition. If Prisma can update their Decimal.js dependency and you can update the direct Decimal.js dependency, that should resolve this issue.
@jon-ressio thanks for putting together the PR - Regarding your (I believe unrelated) import issue. Have you considered importing Decimal using:
However, the duplicate declaration of toStringTag leading to incompatibility will still persist.