Open blueforesticarus opened 2 years ago
Yes, but at that point why have a type at all? Might as well just accept strings in that case.
The original motivation behind a distinct type for Spotify IDs is they are a specifically formatted string and it allows the type system to help distinguish where these IDs are required.
yes, but you can pass a string implicitly to a function demanding a spotify.ID it only doesn't work for functions demanding a slice. It is inconsistant behavior. (to be fair, the inconsistancy is in the golang spec )
there is nothing here that protects you from passing badly formated strings the type IS a slice of string, it should accept a slice of string
it also means I have to write functions like:
func blah(Ids []string) []spotify.ID {
return *(*[]spotify.ID)(unsafe.Pointer(&Ids))
}
func blarg(Ids []spotify.ID) []string {
return *(*[]string)(unsafe.Pointer(&Ids))
}
Just to be able to use the function.
Because ID and URI are not type aliases, you cannot automatically convert a []string of spotify ids into a []spotify.ID when calling functions like GetAlbums.
If they were defined as aliases, the type conversion would be automatic. see here