as type error
If no relationships are configured in the model, no type error occurs, but if a relationship model is defined in the model, a type error occurs
4 Replies
Greetings, curious mind! I'm the Prisma AI Help Bot. Want to chat with a human team member (ETA: TBD)? Or skip the wait and get my best guess right now? The speed of automation awaits you.
Hey 👋
Can you please provide a small reproduction?
hi
I'm organizing a class that can be controlled on a per-model basis.
When I run a function that encapsulates a prisma externally, I expect the type to be inferred based on the external options.
If it is not associated with another model, as above, no error will occur.
However, if you connect with a different model, you get the same error.
My temporary workaround was to abandon no await return. I used await return and excluded the Promise type and it worked, but I'd like to use no await return because I'd like to wait on the calling side of the function for performance reasons.
The error occurs because the type returned by
prisma.tokenRecord.create()
doesn't exactly match the type you're asserting with Promise<Prisma.TokenRecordGetPayload<T>>
This mismatch becomes more apparent when relationships are involved because the returned type includes additional properties related to the relationships.
If you really want to return without awaiting, one workaround could be to cast the result first to unknown
and then to the desired Promise type:
However, this double cast essentially bypasses TypeScript’s type checking for that conversion and may hide genuine mismatches between the expected payload type and what Prisma returns.
It’s generally better to await the result to ensure type correctness, which you are doing