-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect export class generation for typescript from golang struct #2602
Comments
Confirmed over here as well..
Resulting models.ts:
|
Can you please try |
I have just tried the master branch but the issue still seems to be there. I have added the following line to go.mod in my project: I tried looking into the issue myself, but whenever I run What am I doing wrong? Is there anything else that I need to do? |
@phyce use |
Still happening with Wails v2.8.1. type Post struct {
UUID string `json:"uuid"`
AuthorUUID string `json:"author_uuid"`
Text string `json:"text"`
Reasoning string `json:"reasoning"`
Created time.Time `json:"created"`
Error error `json:"error"`
} export class Post {
uuid: string;
author_uuid: string;
text: string;
reasoning: string;
created: time.Time;
error: any;
static createFrom(source: any = {}) {
return new Post(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.uuid = source["uuid"];
this.author_uuid = source["author_uuid"];
this.text = source["text"];
this.reasoning = source["reasoning"];
this.created = this.convertValues(source["created"], time.Time);
this.error = source["error"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
} Is there anything I could do? It works - I am able to access Created in typescript, just the |
I tried recently and still had the same issue - a workaround I did was to simply not have the json export tags on the struct, and creating it manually in typescript |
Description
This issue happens with versions 2.3.1 and 2.4.1
I have a project with Typescript + Wails.
The generated code in models.ts fails to build when adding json tags to a struct in which one of the Items is of type []time.Time
To Reproduce
Expected behaviour
I assume that the generated type for
CalendarStartupDates
should beany[]
instead oftime.Time[]
.Screenshots
No response
Attempted Fixes
Removing the json tags from the struct stops the build from failing.
I have a custom interface for this data in my code so I don't really need it, but there doesn't seem to be any other way to stop this from being generated.
System Details
Additional context
I stumbled upon this problem because I need the json tags in Go so that I can export data in json format to a file.
Also on a side note, wails doctor reports the OS is windows 10, when it's actually windows 11.
The text was updated successfully, but these errors were encountered: