I'm writing a function for calling into JavaScript from Swift and would like to accept the name of a function and a list of arguments to call with. The list should be able to contain anything that I can convert into JSON.

e.g.

```
callJS(function: "console.log", withArgs: [1, "Hello"])

```

My naive attempt at this was this:

```
func callJS(function: String, withArgs args: [Encodable]) {
    let encoder = JSONEncoder()
    let data = try! encoder.encode(list)
    let jsonArgs = String(data: data, encoding: .utf8)

    executeJS("\(function)(...\(jsonArgs))")
}

```

Unfortunately, that fails at runtime with the following fatal error:

> 
> Fatal error: Array does not conform to Encodable because Encodable does not conform to itself. You must use a concrete type to encode or decode.
> 
> 
> 

Is there any way to get the compiler to embed the types from the call sites, so that `Encodable` knows what to encode?