When trying to use any
instead of interface{}
with the Go 1.18 toolchain, you can get the error:
undeclared name: any (requires version go1.18 or later)
Why is that, and how can you solve it? any
was introduced in Go 1.18.
When trying to use any
instead of interface{}
with the Go 1.18 toolchain, you can get the error:
undeclared name: any (requires version go1.18 or later)
Why is that, and how can you solve it? any
was introduced in Go 1.18.
You will get this error if your go.mod file lists a go
version below 1.18, such as:
module example.com/foo
go 1.17
Changing your go.mod to instead read go 1.18
should resolve the error.
In general, each module's go.mod file controls the version of the Go language that is used when compiling that module, which allows for a more gradual adoption of new language changes with each module author opting in at their own pace. This is described in more detail in the Go language changes design document.
Example of this error on the playground, including a go.mod file you can edit: https://go.dev/play/p/au6TtTvNsRy
© 2022 - 2024 — McMap. All rights reserved.