英文:
How to disable errors in VS Code (gopls) when writing code in go1.18beta?
问题
想要使用go1.18beta
版本的泛型特性来在一个中心函数中处理错误。
错误处理函数示例:
func HandleError[T any](t T, err error) T {
if err != nil {
panic(err)
}
return t
}
第一个抛出的错误是:
expected '(', found '['
第二个抛出的错误是:
not enough arguments in call to HandleError (compiler) (WrongArgCount)
我知道 gopls 是基于 go1.17
的,这就是为什么会出现这些错误,但是否有办法禁用这些错误,就像在 TypeScript 中那样?
英文:
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?
答案1
得分: 1
你可以按照这里描述的方式,使用1.18版本的Go构建gopls:
https://github.com/golang/tools/blob/master/gopls/doc/advanced.md#working-with-generic-code
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论