Skip to content

javascript to golang: confusing double casting is necessary for EventsOn callback #1324

Description

@benjamin-thomas

Description

Hello,

I'm testing out your tool (which I find very enjoyable to use: congrats), and I've hit a little nail which is possibly a bug or at least would require a little more documentation here: https://wails.io/docs/howdoesitwork#calling-runtime-methods

I'm running on Wails CLI v2.0.0-beta.34 on Ubuntu 20.04.

I hope the screenshots below will be clear enough for you.

To Reproduce

Following the demo, I want to report a message from the frontend to the backend as soon as I click on the Greet button:

image

To do this, I trigger a custom event from the JS side:

image

However, after much fiddling, it seems that I have to double cast the slice of interfaces, which seems very odd

image

image

Expected behaviour

Could you please clarify if this is intended behavior?

I would expect line 68 to work.

In order to extract a second argument, I found that I also had to apply the same clunky double casting to it.

So unless I'm misunderstanding something, there seems to be a buggy behavior here: casting the first item of a slice of interfaces to a slice of interfaces in order to retrieve its singular value at index zero does not make sense.

I'm getting back into golang after a few years off so I hope I'm not doing something stupid and this won't be a dumb bug report ;)

Screenshots

No response

Attempted Fixes

  • google search
  • search more info in the docs
  • tried to find a working example in the wild via sourcegraph (did not find any)
  • searched these github issues

System Details

Wails CLI v2.0.0-beta.34


Scanning system - Please wait (this may take a long time)...Done.

System
------
OS:                     Ubuntu
Version:                20.04
ID:                     ubuntu
Go Version:             go1.18
Platform:               linux
Architecture:           amd64
Package Manager:        apt

Dependency      Package Name            Status          Version
----------      ------------            ------          -------
*docker         docker.io               Installed       20.10.7-0ubuntu5~20.04.2
gcc             build-essential         Installed       12.8ubuntu1.1
libgtk-3        libgtk-3-dev            Installed       3.24.20-0ubuntu1.1
libwebkit       libwebkit2gtk-4.0-dev   Installed       2.34.6-0ubuntu0.20.04.1
npm             npm                     Installed       8.5.0
*nsis           nsis                    Installed       v3.05-2
pkg-config      pkg-config              Installed       0.29.1-0ubuntu4

* - Optional Dependency

Diagnosis
---------
Your system is ready for Wails development!

Additional context

On a side note, I was confused by not being able to replace any mention of interface{} to any in the signature, or face a server crash and won't start.

I understood any is an alias to interface{} in go 1.18 so this is probably something you're already aware of and will fix later?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions