-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): make nested omit types work (#25900)
When we have nested `select` or `include`, TypeScript at some point gives up remembering what keys `A` has exactly and discards the `omit` for whatever reason. Re-adding the `omit` key at the point it happens using the `A & { omit: A['omit'] }` hack makes TypeScript a little bit less forgetful. Closes: prisma/team-orm#1442 Fixes: #24835 Co-authored-by: Jacek Malec <malec@prisma.io>
- Loading branch information
1 parent
509b064
commit ebda0b9
Showing
4 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineMatrix } from '../_utils/defineMatrix' | ||
import { allProviders } from '../_utils/providers' | ||
|
||
export default defineMatrix(() => [allProviders]) |
41 changes: 41 additions & 0 deletions
41
packages/client/tests/functional/24835-omit-error/prisma/_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { idForProvider } from '../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["omitApi"] | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model A { | ||
id ${idForProvider(provider)} | ||
model_b B[] | ||
} | ||
model B { | ||
id ${idForProvider(provider)} | ||
a_id String | ||
a A @relation(fields: [a_id], references: [id]) | ||
private_field String | ||
c_id String | ||
c C @relation(fields: [c_id], references: [id]) | ||
} | ||
model C { | ||
id ${idForProvider(provider)} | ||
public_field String | ||
B B[] | ||
} | ||
` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
|
||
testMatrix.setupTestSuite(() => { | ||
test('have omitted field as never', async () => { | ||
const example = await prisma.a.findFirst({ | ||
include: { | ||
model_b: { | ||
include: { | ||
c: true, | ||
}, | ||
omit: { | ||
private_field: true, | ||
}, | ||
}, | ||
}, | ||
omit: { id: true }, | ||
}) | ||
|
||
// @ts-expect-error | ||
example?.model_b[0].private_field | ||
}) | ||
}) |