Skip to content
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

Typing is wrong in Fluent API on optional types when findUniqueOrThrow is used (null type becomes never) #18259

Open
qortex opened this issue Mar 8, 2023 · 0 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: fluent api

Comments

@qortex
Copy link

qortex commented Mar 8, 2023

Bug description

model Person {
  id       String @id

  optionalInfo OptionalInfo?
}

model OptionalInfos { ... }

Now, let's try to access optionalInfos on a Person we know exists:

const optInfo = await this.prisma.person
      .findUniqueOrThrow({ where: { id: existingId } })
      .optionalInfo();

Type of optInfo should be OptionalInfo | null. But it incorrectly is OptionalInfo.

Using findUnique to access Person instead of findUniqueOrThrow correctly implies typing is OptionalInfo | null.

This comes from the fact the the Null type in Prisma Client seems to be set for the topmost call and then cascade to the rest of the call. This is not correct behavior for the fluent API.

Related to, but not a duplicate of: #8929

How to reproduce

See Above

Expected behavior

In both cases, type should be OptionalInfo | null, or even OptionalInfo | null | undefined, to account for a Person not found.

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: 18

Prisma Version

prisma                  : 4.8.0
@prisma/client          : 4.8.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe
Default Engines Hash    : d6e67a83f971b175a593ccc12e15c4a757f93ffe
Studio                  : 0.479.0
@qortex qortex added the kind/bug A reported bug. label Mar 8, 2023
@janpio janpio added topic: fluent api bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. labels Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: fluent api
Projects
None yet
Development

No branches or pull requests

2 participants