传播时“不能将[] struct类型的变量用作[]接口”

Prototype function

func test(i ...interface{}) {
    // Code here
}

Intended use

type foo struct {
    // Fields
}

foos := []foo{
    // foo1, foo2 ...
}

test(foos...) // ERROR
test(foos[1], foos[2], ...) // OK

Error

cannot use foos (variable of type []foos) as []interface{} value in argument to test

Description

The intended use is to be used like the built-in function append().

https://golang.google.cn/pkg/builtin/#append

func append(slice []Type, elems ...Type) []Type

Although, as I've seen append() doesn't use interface{}, which is strange, since anywhere that I searched all people say to use interface{} when you don't know the type. But they don't. Nope, append() uses a "build-in" type called Type, which apparently the docs say that it's a int. Although, I cannot use it. There isn't such type. And neither I would know how to use it if there was.

https://golang.google.cn/pkg/builtin/#Type

type Type int

So, I'm very confused here.

Questions

  1. Why does the spread operator not work as intended? For example, in Javascript the spread operator just spreads the array into items. But in Golang it seems like it keeps the same array parameter type as it is but gives the compiler later an instruction to spread it. Which is odd.

  2. Are we even able to make similar custom mechanisms like append() at all? Or am I a dummy and I'm using something wrong anyway?

I think that this is the issue that you are running into here.

https://github.com/golang/go/wiki/InterfaceSlice

I am not an expert in this but have hit this before, the "slice of empty interface" is not an interface and therefore cannot be replaced by any type which is the issue that you are having, it has to do with the memory structure being different. The above has a far better explanation than one that I can give.