Unwrap error from type

Can I unwrap error from a return type?

fn my_fn(elem: anytype) @unwrapError(@TypeOf(elem)) {
    return elem catch unreachable;
}

unwrapError is a imaginary builtin fn. I already searched on docs and nothing…

fn my_fn(elem: anytype) @typeInfo(@TypeOf(elem)).error_union.payload {
    return elem catch unreachable;
}
4 Likes