wails
wails copied to clipboard
Bindings: Field that starts with special characters generates wrong binding
Description
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:
> [email protected] 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
and then npm run build
which makes it work
Screenshots
No response
Attempted Fixes
I have a possible fix ready https://github.com/wailsapp/wails/compare/master...Gjergj:wails:special_chars_bindings but I'm unsure on the typescript part
System Details
# 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_