TypeScript Error TS2322 when assigning JavaScript Date object to Prisma DateTime field #20253
Labels
5.0.0
bug/2-confirmed
Bug has been reproduced and confirmed.
kind/bug
A reported bug.
team/client
Issue for team Client.
tech/typescript
Issue for tech TypeScript.
topic: clientExtensions
topic: dates / DateTime
topic: prisma-client
Milestone
Bug description
From Prisma v4.16.2, I am experiencing an issue when using Prisma Client extensions in combination with the Date type in TypeScript.
I created a custom factory to create User objects using the extended Prisma client (orm)
When attempting to use the Date object for the updated_at field, I am running into a TypeScript error (TS2322):
TS2322: Type 'Date' is not assignable to type 'Exact<string | Date, string | Date>'. Type 'Date' is not assignable to type '{ toString: {}; toDateString: never; toTimeString: never; toLocaleString: never; toLocaleDateString: never; toLocaleTimeString: never; valueOf: {}; getTime: never; getFullYear: never; getUTCFullYear: never; ... 33 more ...; [Symbol.toPrimitive]: never; }'. Types of property 'toDateString' are incompatible. Type '() => string' is not assignable to type 'never'. index.d.ts(1888, 5): The expected type comes from property 'updated_at' which is declared here on type 'Exact<{ id?: string | undefined; name: string; created_at?: string | Date | undefined; updated_at: string | Date; }, (Without<usersCreateInput, usersUncheckedCreateInput> & usersUncheckedCreateInput) | (Without<...> & usersCreateInput)'
It appears that the Date type isn't being correctly recognized or compatible with the extended Prisma client. I expect to be able to assign a JavaScript Date object to the updated_at field without a TypeScript error.
When using the prisma client without extensions, it works just fine.
This issue occurs in a minimal reproducible example (repository), which I have included as an attachment.
Environment:
Node.js: 18.16.0
TypeScript: 5.1.6
Prisma: 5.0.0
Looking forward to your support in resolving this issue. Thank you!
How to reproduce
Expected behavior
The expected behavior is that I should be able to assign a new Date() to the 'updated_at' field without TypeScript errors. This is because the 'updated_at' field in the Prisma schema is of type DateTime, which should be compatible with the JavaScript Date object. However, the current behavior shows a TypeScript error instead.
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: