wails: `models.ts` is not generated.

Description

When I run wails dev, I expect frontend/wailsjs/go/models.ts to be generated, but it is not. I use wails version v2.0.0-beta.35.

To Reproduce

  1. Execute wails init -t svelte-ts -d foo -n bar.
  2. Execute cd foo.
  3. Add the following to app.go.
type Foo struct{}

func (a *App) Foo() *Foo {
	return &Foo{}
}
  1. Execute wails dev.
  2. I look for frontend/wailsjs/go/models.ts but can’t find it.

Expected behaviour

frontend/wailsjs/go/models.ts is generated.

Screenshots

No response

Attempted Fixes

In wails version v2.0.0-beta.34 frontend/wailsjs/go/models.ts is generated.

System Details

Wails CLI v2.0.0-beta.35


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

System
------
OS:             Windows 10 Home
Version:        2009 (Build: 19044)
ID:             21H2
Go Version:     go1.18.1
Platform:       windows
Architecture:   amd64

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

Dependency      Package Name    Status          Version
----------      ------------    ------          -------
WebView2        N/A             Installed       100.0.1185.50
npm             N/A             Installed       8.5.5
*upx            N/A             Installed       upx 3.96
*nsis           N/A             Available

* - Optional Dependency

Diagnosis
---------
Your system is ready for Wails development!
Optional package(s) installation details:
  - nsis : Available at https://nsis.sourceforge.io/Download

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

Hi, does your struct have json tags? Wails will only create the models.ts if your go struct has associated json:“” tags and if it exported like:

type MyStruct struct {
    ID string `json:"id"`
}

I only become aware of Wails recently thanks to the Golang Weekly newsletter. Got a little personal project it’s perfect for and I’ve started on. Once I have a bit more familiarity, and if somebody hasn’t started on it already, I’ll happily take that on.

I’d prefer this approach for sure but remember it did not working correctly for some reason back in the day. If you are happy to look at it, please open a ticket and we can stick it on the board 👍

I forgot to mention an issue that should have been mentioned. The following code App.d.ts is generated by following the steps shown in the introduction.

// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';

export function Foo():Promise<main.Foo>;

export function Greet(arg1:string):Promise<string>;

../models is imported, but it does not exist. It is incomplete as source code. There is a issue with this condition. I would like you to generate an empty Foo class as follows.

export namespace main {
	
	export class Foo {
	    id: string;
	
	    static createFrom(source: any = {}) {
	        return new Foo(source);
	    }
	
	    constructor(source: any = {}) {
	        if ('string' === typeof source) source = JSON.parse(source);
	    }
	}

}

Or , if it generates incomplete code, it should output a warning to the CLI when it runs wails dev at minimum.

~So @leaanthony and @mondy - is this expected behaviour? I was following the getting started guide and ran into the same issue where App.d.ts was showing an import for models but models.ts was nowhere to be found. This was on v2.0.0-rc.1.1.~

Sorry for the noise, it was a snafu on my end. model.ts is indeed generated.

I’m wondering if it’s more desirable to leave it so it doesn’t compile, as that will tell you that you’ve got something wrong in your code. Or…we could generate a blank model with a comment that warns about this and has a link to the docs… that actually sounds reasonable to me.