Skip to content

fix(v2): generate nested TS types for embedded structs with named JSON tags#5221

Draft
leaanthony wants to merge 1 commit intomasterfrom
fix/4117-embedded-struct-bindings
Draft

fix(v2): generate nested TS types for embedded structs with named JSON tags#5221
leaanthony wants to merge 1 commit intomasterfrom
fix/4117-embedded-struct-bindings

Conversation

@leaanthony
Copy link
Copy Markdown
Member

Summary

  • Fixes TypeScript binding generation for Go structs with embedded (anonymous) struct fields that have named JSON tags
  • Previously, TimeLimitDef \json:"timeLimitDef"`` would be flattened into the parent TS class, but Go's JSON encoder produces a nested object — causing deserialization mismatches
  • Two fixes:
    1. deepFields() in typescriptify.go: checks for named JSON tags before flattening embedded structs
    2. AddStructToGenerateTS() in binding.go: allows anonymous fields with named JSON tags through for struct type registration

Test plan

  • New test binding_named_embedded_struct_test.go verifies that StructWithNamedEmbeddedStruct generates:
    • Separate InnerStruct and AppInfo TS classes
    • Properly nested fields (timeLimitDef: InnerStruct, application: AppInfo) in the parent class
  • All 30+ existing binding tests continue to pass (anonymous inline structs still produce any as before)

Fixes #4117

…N tags

When a Go struct has an embedded (anonymous) struct field with a named
JSON tag (e.g. TimeLimitDef `json:"timeLimitDef"`), Go's JSON
encoder produces a nested object. But the TS binding generator was
incorrectly flattening these fields into the parent class, causing
deserialization failures.

Fix in two places:
- deepFields() in typescriptify.go: check for named JSON tags before
  flattening embedded structs; treat named-tag embeds as regular fields
- AddStructToGenerateTS() in binding.go: allow anonymous fields with
  named JSON tags through for struct registration

Fixes #4117
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a75e248-a116-4bcb-a476-23ff1a481fa6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4117-embedded-struct-bindings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@leaanthony
Copy link
Copy Markdown
Member Author

🤖 PR Triage Review

Accepted

Generates nested TS types for embedded structs with named JSON tags (v2 bindings). Improves TypeScript type safety.

Platform: All (v2, bindings)

Next Steps: Dispatching for testing on all platforms.


Reviewed by Wails PR Reviewer Bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v2.9.0] generate module ts will error if go struct with nest sub struct,with named json tag

1 participant