t
tRPC
t
tRPC
Cannot infertype of prisma in client
Original message was deleted
tRPC
Join
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,111
Members
View on Discord
B
backbone
•
3/17/23, 4:29 PM
Could you show the detail of getRegistrant function
?
B
backbone
•
3/17/23, 4:31 PM
Typescript can not infer types if you return different data by random input
B
backbone
•
3/19/23, 3:23 AM
Try only return registrant and no if no throw error
N
Nick
•
3/19/23, 9:52 AM
You
’re returning a single or an array right
?
N
Nick
•
3/19/23, 9:52 AM
Typescript doesn
’t know which one you received unless you check on the client with Array
.isArray
N
Nick
•
3/19/23, 9:53 AM
It
’s a
“union
” type
N
Nick
•
3/19/23, 2:13 PM
Why would it fix it
? You
’re now trying to access name on something guaranteed to be an array right
?
N
Nick
•
3/19/23, 2:14 PM
The error message typescript spits out is a little complex because your type is complex
, but it
’s actually giving you the information you need
N
Nick
•
3/19/23, 2:15 PM
Property name does not exist on YOURTYPE
[
]
N
Nick
•
3/19/23, 2:55 PM
Do what
's right for your needs
N
Nick
•
3/19/23, 2:55 PM
It will probably make your life easier by pushing the decision to the frontend
, but also it might not
N
Nick
•
3/19/23, 2:56 PM
Learn to narrow types
/ unions in typescript and both methods are fine
N
Nick
•
3/19/23, 3:01 PM
No problem