You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go structs which contains fields with json tags such as json:"@ID,omitempty" generate wrong typescript class.
To Reproduce
This struct
type MyStruct struct {
ID string `json:"@ID,omitempty"`
}
Generates this binding:
export namespace main {
export class MyStruct {
"@ID?"?: string;
static createFrom(source: any = {}) {
return new MyStruct(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this["@ID"] = source["@ID"];
}
}
}
Where field name "@ID?" is wrong. Notice the extra question mark in the variable name.
And gives this error
❯ wails dev
Wails CLI v2.8.1
Executing: go mod tidy
• Generating bindings: Done.
• Installing frontend dependencies: Done.
• Compiling frontend:
> frontend@0.0.0 build
> vue-tsc --noEmit && vite build
wailsjs/go/models.ts(12,15): error TS2551: Property '@ID' does not exist on type 'MyStruct'. Did you mean '@ID?'?
ERROR exit status 2
♥ If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony
Expected behaviour
Expected behaviour is to generate
export namespace main {
export class MyStruct {
"@ID"?: string;
static createFrom(source: any = {}) {
return new MyStruct(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this["@ID"] = source["@ID"];
}
}
}
To make it work I've added an command in the frontend:build step which executes this replace first
sed -i '' "s/@ID?/@ID/g" myproject/frontend/wailsjs/go/models.ts
# Wails
Version | v2.8.1
# System
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS | MacOS || Version | 14.4.1 || ID | 23E224 || Go Version | go1.22.1 || Platform | darwin || Architecture | arm64 || CPU | Apple M1 Pro || GPU | Chipset Model: Apple M1 Pro Type: GPU Bus: Built-In Total Number of Cores: 14 Vendor: Apple (0x106b) Metal Support: Metal 3 || Memory | 32GB |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
# Dependencies
┌───────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status | Version || Xcode command line tools | N/A | Installed | 2406 || Nodejs | N/A | Installed | 21.7.1 || npm | N/A | Installed | 10.5.0 ||*Xcode | N/A | Installed | 15.3 (15E204a) ||*upx | N/A | Available |||*nsis | N/A | Available ||
└─────────────────────── * - Optional Dependency ───────────────────────┘
# Diagnosis
Optional package(s) installation details:
- upx : Available at https://upx.github.io/
- nsis : More info at https://wails.io/docs/guides/windows-installer/
SUCCESS Your system is ready for Wails development!
♥ If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony
### Additional context
_No response_
The text was updated successfully, but these errors were encountered:
Description
Go structs which contains fields with json tags such as
json:"@ID,omitempty"
generate wrong typescript class.To Reproduce
This struct
Generates this binding:
Where field name
"@ID?"
is wrong. Notice the extra question mark in the variable name.And gives this error
Expected behaviour
Expected behaviour is to generate
To make it work I've added an command in the
frontend:build
step which executes this replace firstand then
npm run build
which makes it workScreenshots
No response
Attempted Fixes
I have a possible fix ready master...Gjergj:wails:special_chars_bindings but I'm unsure on the typescript part
System Details
The text was updated successfully, but these errors were encountered: