Not sure generic type alias is the solution, but what I'm trying to do is I
have a type like this
type Map[K comparable, V any] struct { m map[K]V }
and I want it to implement json.Unmarshaller to decode json objects, when
K's underlying type is string:
type omap[K ~string, V any] = Map[K, V]
func (m *omap[K, V]) UnmarshalJSON(data []byte) error {
k := "a"
v :=1
m[K(k)] = v
}
Go 1.23 with the aliastypeparams flag enabled, currently complains "cannot
convert k (variable of type string) to type K".
I wonder if using alias this way is wrong and if there exists another
solution?
--
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/d349ca09-7b2b-43bf-a069-c35db3fa27f1n%40googlegroups.com.