Home > Back-end >  How to disable errors in VS Code (gopls) when writing code in go1.18beta?
How to disable errors in VS Code (gopls) when writing code in go1.18beta?

Time:01-11

Want to use go1.18beta for its generics feature to handle errors in a central function.

Error handling function example

func HandleError[T any](t T, err error) T {
    if err != nil {
        panic(err)
    }
    return t
}

The first error thrown is

expected '(', found '['s

The second error thrown is

not enough arguments in call to HandleError (compiler) (WrongArgCount)

I am aware that gopls is of go1.17 and that's why it's throwing errors but is there any way to disable these errors as we do in typescript?

CodePudding user response:

You can build a gopls with 1.18 go as described here: https://github.com/golang/tools/blob/master/gopls/doc/advanced.md#working-with-generic-code

  •  Tags:  
  • Related