Repository navigation
Closed
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.tech/typescriptIssue for tech TypeScript.topic: client typesTypes in Prisma Clienttopic: update()
Description
Bug description
When calling update, any type can be passed to data:
prisma.user.update({
where: {
id: 1,
},
data: 10, // should trigger a type error
})
Null or Undefined trigger Typescript errors but strings or numbers don't.
There might be something wrong with the XOR type definition:
import { Prisma } from '@prisma/client'
type XOR<T, U> = T extends object
? U extends object
? (Without<T, U> & U) | (Without<U, T> & T)
: U
: T
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }
type TestType = XOR<Prisma.UserUpdateInput, Prisma.UserUncheckedUpdateInput>
const fn = (a: TestType) => {}
const fn1 = (a: Prisma.UserUpdateInput) => {}
const fn2 = (a: Prisma.UserUncheckedUpdateInput) => {}
fn(5) // No errors
fn1(5) // Type '5' has no properties in common with type 'UserUpdateInput'.ts(2559)
fn2(5) // Type '5' has no properties in common with type 'UserUncheckedUpdateInput'.ts(2559)
How to reproduce
I just followed the Getting started.
- Create model as below
npx prisma generate
Expected behavior
A type error should be raised when anything but an object matching the table type is passed.
Prisma information
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
Environment & setup
- OS: Any
- Database: Any
- Node.js version: 18.17.1
Prisma Version
prisma : 5.7.0
@prisma/client : 5.7.0
Computed binaryTarget : darwin
Operating System : darwin
Architecture : x64
Node.js : v18.17.1
Query Engine (Node-API) : libquery-engine 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Schema Engine : schema-engine-cli 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/@prisma/engines/schema-engine-darwin)
Schema Wasm : @prisma/prisma-schema-wasm 5.7.0-41.79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Default Engines Hash : 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Studio : 0.495.0
Reacted by Valentin Hervieu, Domagoj Vukovic and Artemiy Prikupets
Metadata
Metadata
Assignees
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.tech/typescriptIssue for tech TypeScript.topic: client typesTypes in Prisma Clienttopic: update()
Activity
jkomyno commentedon Feb 16, 2024
Hi @yns01, both with
[email protected]and our latest version,[email protected], I correctly. see the following output when running the snippet above:However, it seems that TypeScript Language Server on VSCode isn't able to display that there is a type mismatch. Thank you for opening this issue, we'll investigate.
Jolg42 commentedon Feb 16, 2024
This looks like a duplicate of #9988, but since this is now confirmed & reproduced here, let's keep this one open and close the old one.
[-]No typing error when passing a string or a number to data for update()[/-][+]No typing error when passing a string or a number to data for `update()`[/+]fix(client): reject non-object values in XOR type helper (prisma#29735)
fix(client): reject non-object values in XOR type helper (prisma#29735)