You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On my client app when I intentionally pass an invalid param, I get a typechecking error as I would expect:
const re = await api.greet[':person'].$get({
// ts error: 'bill' is not assignable to type 'john'
param: { person: 'bill' },
});
The inferred type is the result from a successful response, but the actual response is an error which is not inferred at all even if I try narrowing:
// re.ok === false
const data = await re.json();
if (!re.ok) {
// Does not infer data.name === 'ZodError', only data.result (which doesn't exist)
...
}
return {
// data.result doesn't exist if there was a Zod validation error, but typescript thinks it does!
greeting: data.result,
};
I'm just completely stuck on this and could use some insight.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm struggling with type inference when using a validator like zValidator and the RPC approach.
On my server, I have the chained response (like docs recommend) with a simple param validator:
On my client app when I intentionally pass an invalid param, I get a typechecking error as I would expect:
The inferred type is the result from a successful response, but the actual response is an error which is not inferred at all even if I try narrowing:
I'm just completely stuck on this and could use some insight.
Beta Was this translation helpful? Give feedback.
All reactions