Why select() always expects to have matches?
hi. i encountered this issue:
record
is inferred to have a non-nullable type, even though the queried record with the ID 123456 may not exist in the database.
Can anyone tell me if I am doing something wrong?
I was migrating some queries to select() but this behavior makes it pretty unusable 😕
Thanks4 Replies
Make sure you have
noUncheckedIndexedAccess: true
in your tsconfig.json file
In TypeScript without that option, when you have an array like
string[]
for example, string[0]
is string
. However, the array could be empty. That's where the option comes in and makes it string | undefined
unless you check that the index exists.
The same is true for objects with unknown keys like const obj: Record<string, string> = {}
thanks, however now I'm getting a couple of rather curious errors. I don't like typescript very much 😪