This may not be what you want, but starting from Go 1.9 it's possible to declare a type alias using the syntax
type MyString = string As opposed to a type definition, an alias declaration doesn't create a new distinct type different from the type it's created from. Type aliases are not meant to be an everyday feature of Go, but are intended to be used during large and complex code refactoring. On Sunday, June 25, 2017 at 2:16:23 AM UTC+2, Ivan Bertona wrote: > > Hello, > > When I try to compile this piece of code: > > package main > > type MyString string > type MyBytes []byte > > func GetString() (string, error) { > return "", nil > } > > func GetBytes() ([]byte, error) { > return nil, nil > } > > func main() { > var s MyString > var b MyBytes > var err error > > s, err = GetString() > b, err = GetBytes() > } > > I get this error: tmp/sandbox008752331/main.go:19: cannot assign string to > s (type MyString) in multiple assignment > > Does anyone know why implicit casting from []byte to MyBytes works, but it > doesn't for string to MyString? > > Best, > Ivan > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.