Re: [go-nuts] cannot initialize 1 variables with 2 values

147 views
Skip to first unread message
Message has been deleted

Kurtis Rader

unread,
Nov 23, 2022, 8:54:25 PM11/23/22
to Denis P, golang-nuts
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....@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...@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.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Reply all
Reply to author
Forward
0 new messages