How to get output with safeParse without checking for success #282
-
Hello! My first question here. I'm trying to get the output out of safeParse without checking directly for success but after checking for not success. Let me explain myself. const data = ...;
const someSchema = schema(...);
const result = safeParse(someSchema, data);
if (!result.success) {
// Throw some error
}
// This should probably work, we already went through "not success"
const MyObject = result.output The above snipet shows that output doesn't exist if we're not checking directly for success. I have a relatively huge amount of code that should happen when it's parsed successfuly but I don't want to enclose all of it inside a Am I doing something wrong? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Your approach works fine for me. Did you set |
Beta Was this translation helpful? Give feedback.
I think TypeScript needs to see the
throw
statement. So you could change your code like this: