Let\'s say I have two similar types set this way :
type type1 []struct {
Field1 string
Field2 int
}
type type2 []struct {
Field1 string
Field
To give a reference to OneOfOne's answer, see the Conversions section of the spec.
It states that
A non-constant value
xcan be converted to typeTin any of these cases:
xis assignable toT.x's type andThave identical underlying types.x's type andTare unnamed pointer types and their pointer base types have identical underlying types.x's type andTare both integer or floating point types.x's type andTare both complex types.xis an integer or a slice of bytes or runes andTis a string type.xis a string andTis a slice of bytes or runes.
The first and highlighted case is your case. Both types have the underlying type
[]struct { Field1 string Field2 int }
An underlying type is defined as
If
Tis one of the predeclared boolean, numeric, or string types, or a type literal, the corresponding underlying type isTitself. Otherwise,T's underlying type is the underlying type of the type to whichTrefers in its type declaration. (spec, Types)
You are using a type literal to define your type so this type literal is your underlying type.