In my case, the underlying type is not struct.

// Device contains strings of the device name
type Device string

// NativeDevice stands for smartphone app(e.g. iOS/Android)
type NativeDevice Device

// AppleDevice stands for iOS device.
type AppleDevice NativeDevice


// Error pattern: using `struct type` for AppleDevice.
func NewIPhoneDevice() AppleDevice {
    return AppleDevice{}  // => Error: invalid type for composite literal.
}

// Corrent pattern: using `string type` for AppleDevice.
func NewIPhoneDevice() AppleDevice {
    return "iphone" // use `string`
}

https://play.golang.org/p/cLSmvB4bZD2

Leave a Reply

Your email address will not be published. Required fields are marked *