Infer properly Error of a Result #82
-
Hello, I have three functions : It isn't possible to infer errors from a function ? I've tried to do Any idea ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@Nainterceptor Could you create an exemple in the Typescript playground? That's not super clear. |
Beta Was this translation helpful? Give feedback.
@Nainterceptor That's normal, because in your example, you have this:
And this:
But
typeof Child1
andtypeof Child2
are not of typeResult
, but of type() => Result<null, Child1Error>
and() => Result<null, Child2Error>
.To fix it, you can ever either use
ReturnType
:Or change your
InferError
(and set a constraint on the generic to have nice reporting in case you pass something else):