wails icon indicating copy to clipboard operation
wails copied to clipboard

Unable to infer types of sub backend packages and some golang data types in wailsjs models.d.ts generation

Open Purple-CSGO opened this issue 3 years ago • 1 comments

Description

Problem 1

My Directory structure is like this:

backend/
  config/
  core/
  app.go
frontend/
main.go

So there are sub/subusb/... packages. In models.d.ts, types from different sub/... packages are divided to different namespaces, but wails does not refer to the namespaces, resulting in typescripts errors. Part of my models.d.ts file is as follows, where Item[] should be tool.Item[]

export namespace tool {
  export class Item {
    name: string;
    value: string;
    ...
  }
}

export namespace config {
  export class CFG {
    ...
    videoSetting: Item[];
    hwinfo: Item[];
  }
}

Problem 2

some go types are incorrectly dealed with.

members: {[key: uint64]: CommonDemoSinglePlayerInfo};

Console output after wails dev/build

wailsjs/go/models.ts(242,22): error TS2304: Cannot find name 'uint64'.

To Reproduce

wails dev or wails build

Expected behaviour

    wailsjs/go/models.ts(58,17): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
    wailsjs/go/models.ts(58,22): error TS2552: Cannot find name 'uint64'. Did you mean 'GLuint64'?
    wailsjs/go/models.ts(186,20): error TS2304: Cannot find name 'Item'.
    wailsjs/go/models.ts(187,14): error TS2304: Cannot find name 'Item'.
    wailsjs/go/models.ts(199,16): error TS2304: Cannot find name 'User'.
    wailsjs/go/models.ts(218,73): error TS2304: Cannot find name 'Item'.
    wailsjs/go/models.ts(219,61): error TS2304: Cannot find name 'Item'.
    wailsjs/go/models.ts(231,65): error TS2304: Cannot find name 'User'.
     ELIFECYCLE  Command failed with exit code 2.

Screenshots

No response

Attempted Fixes

No response

System Details

Wails CLI v2.0.0-beta.44.2

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

System
------
OS:             Windows 10 Pro
Version:        2009 (Build: 22000)
ID:             21H2
Go Version:     go1.18.3
Platform:       windows
Architecture:   amd64

Wails
------
Version:        v2.0.0-beta.44.2

Dependency      Package Name    Status          Version
----------      ------------    ------          -------
WebView2        N/A             Installed       104.0.1293.54
npm             N/A             Installed       8.3.1
*upx            N/A             Installed       upx 3.96
*nsis           N/A             Installed       v3.08

* - Optional Dependency

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

Additional context

No response

Purple-CSGO avatar Aug 20 '22 08:08 Purple-CSGO

Thanks for opening this. There's a test file in the v2/internal/binding directory. Feel free to add tests there showing the bugs and we can fix it 👍

leaanthony avatar Aug 20 '22 08:08 leaanthony

Please try the above PR to see if this fixes your problem. If you are unsure how to do this, please follow this guide. Let us know how you get on 👍

leaanthony avatar Sep 26 '22 08:09 leaanthony

thx, I've tested the PR and it works well.

Purple-CSGO avatar Sep 29 '22 09:09 Purple-CSGO