Repository navigation
Update does not enforce type on data
#9957
|
Hello! I'm new to Prisma and testing it out. I encountered an issue today where an prisma.mything.update({
where: { id: '1' },
data: { invalidField: 42 }, // Does not compile as `invalidField` is not a valid field on `mything`
});
const data = { invalidField: 42 };
prisma.mything.update({
where: { id: '1' },
data: data, // Compiles without issues. Why?
});Can you help me understand why? |
Replies: 3 comments 5 replies
|
Hey @GuiSim 👋! This is definitely unexpected. I'm going to convert this to an issue where our engineering teams will triage and investigate further. Feel free to follow it as we might ask for more information. We really appreciate you pointing this one out 👊. |
|
It's the default behavior of TypeScript and how its type system works. TypeScript checks that the object type strictly matches the expected type when you pass an object literal, but allows any compatible type with extra fields (basically, a subtype) when you pass an identifier. It's possible to override this behavior and always match the type strictly, though, using some type system hacks like this: export type StrictPropertyCheck<T, TExpected, TError> = T extends TExpected
? Exclude<keyof T, keyof TExpected> extends never
? T
: TError
: TExpectedCould you please open an issue? |
|
Hi there, To keep our discussions organized and focused on the most relevant topics, we’re reviewing and tidying up our backlog. As part of this process, we’re closing discussions that have already been marked as answered but remain open. If this discussion still requires further input or clarification, feel free to reopen it or start a new one with updated details. Your contributions are invaluable to the community, and we’re here to help! For more details about our priorities and vision for the future of Prisma ORM, check out our latest blog post: https://www.prisma.io/blog/prisma-orm-manifesto. Thank you for your understanding and ongoing support of the Prisma community! |
Hey @GuiSim 👋!
This is definitely unexpected. I'm going to convert this to an issue where our engineering teams will triage and investigate further. Feel free to follow it as we might ask for more information.
We really appreciate you pointing this one out 👊.