Perhaps explicitly capture the error value? That is,

result, err := GetAsOr[MyObj](services.GetServiceOr())

Alternatively, if you don't care if there is an error replace "err" with
"_" to make that clear.

On Wed, Nov 23, 2022 at 4:34 PM Denis P <denis.puj...@gmail.com> wrote:

> Hi guys,
>
> Does anyone know how to pass it properly and without adding extra lines of
> code?
>
> ```
> func GetAsOr[T any](t interface{}, e error) (T, error) {
>     return t.(T), e
> }
>
> func (s ServiceProvider) GetServiceOr() (interface{}, error) {
>    ....
> }
>
> result := GetAsOr[MyObj](services.GetServiceOr()) // Error: cannot
> initialize 1 variables with 2 values
> ```
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/308dd860-a980-449d-a710-201f074e4358n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/308dd860-a980-449d-a710-201f074e4358n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD8emGL%3DCP1R3Ct5hX4%3DMZr7RENvC-s9HU94Vnf%2B_8nJOg%40mail.gmail.com.

Reply via email to