Skip to content

fix: resolve wrong type inference for AND clauses with include #27640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

naaa760
Copy link

@naaa760 naaa760 commented Jul 13, 2025

Hey, I just made a Pull Request!

What does this PR do?

Fixes #27637

Fixes a TypeScript type inference bug where using AND clauses in where conditions with include would incorrectly return the base model type instead of including the specified relations.

How to test

const assets = await prisma.asset.findMany({
  where: {
    AND: [
      { date: { not: null } },
      { date: { gte: "2024-01-01", lte: "2024-12-31" } }
    ]
  },
  include: { items: true }
})

// Before: assets[0].items would show TypeScript error
// After: assets[0].items is correctly typed

## Root Cause
The `GetFindResult` type was using `Equals<A, any> extends 1` which was too broad and caught cases where TypeScript inferred complex types as `any` due to complexity, causing fallback to `DefaultSelection` (base model without includes).

## Solution
Replaced the type check with a more precise one that only falls back to `DefaultSelection` when the type is explicitly `any`, not when it's complex:

@naaa760 naaa760 changed the title fix: resolve wrong type inference for AND clauses with include (#27637) fix: resolve wrong type inference for AND clauses with include Jul 13, 2025
@CLAassistant
Copy link

CLAassistant commented Jul 13, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ naaa760
❌ nehaaaa8


nehaaaa8 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jacek-prisma
Copy link
Contributor

Hi @naaa760,
It looks like your change has caused a number of tests to fail, could you look into them?

@aqrln
Copy link
Member

aqrln commented Jul 29, 2025

ping @naaa760

@naaa760
Copy link
Author

naaa760 commented Jul 29, 2025

@jacek-prisma and @aqrln
I tried to resolve solve the test cases fail , and some fail due to dependency.

@aqrln
Copy link
Member

aqrln commented Jul 29, 2025

and some fail due to dependency

What do you mean, which ones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Prisma 6.11.1 - wrong type of response if using AND in the WHERE clause and including something
4 participants