Hi everyone. I have a question about nullable stri...
# prisma-client
m
Hi everyone. I have a question about nullable strings and filtering them out and the generated return Type. Given a user like
Copy code
model User {
  email String?
}
and requesting users in the client
Copy code
const users = await prisma.users.findMany({
  where: {
    NOT: {
      email: {
        equals: null,
      },
    },
  },
})
Is it possible to get a returned type of?
Copy code
{ email: string }[]
The current return type I am getting is
Copy code
{ email: string | null }[]
r
@Michael B 👋 Unfortunately not, as TypeScript types generated depend on the Prisma schema and not the query that you make. It would be great if you could create a feature request for this so that we can see if this is possible.
Although you can add a custom type of your own like this:
Copy code
import { User } from '@prisma/client'

const users = (await prisma.users.findMany({
  where: {
    NOT: {
      email: {
        equals: null,
      },
    },
  },
})) as UsersWithEmail[]

type UsersWithEmail = User & { email: string }
m
Thanks Ryan, I’ll add it as a feature request
👍 1