Skip to content
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

Bindings: Field that starts with special characters generates wrong binding #3464

Closed
Gjergj opened this issue May 8, 2024 · 1 comment
Closed
Labels
Bug Something isn't working

Comments

@Gjergj
Copy link
Contributor

Gjergj commented May 8, 2024

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:     
    > 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

and then npm run build which makes it work

Screenshots

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

# 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_
@Gjergj Gjergj added the Bug Something isn't working label May 8, 2024
@Gjergj
Copy link
Contributor Author

Gjergj commented May 14, 2024

Thanks for looking into this @atterpac .
Closing this

@Gjergj Gjergj closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant