Skip to content

fix(v2): align generic pointer TypeScript names#5599

Open
sjh9714 wants to merge 1 commit into
wailsapp:masterfrom
sjh9714:fix-v2-generic-pointer-ts-name
Open

fix(v2): align generic pointer TypeScript names#5599
sjh9714 wants to merge 1 commit into
wailsapp:masterfrom
sjh9714:fix-v2-generic-pointer-ts-name

Conversation

@sjh9714

@sjh9714 sjh9714 commented Jun 14, 2026

Copy link
Copy Markdown

Description

Fixes #5160.

The v2 binding generator already strips * from generic type arguments when writing App.d.ts, but models.ts kept the * while deriving model class names. This made Message[*string] generate a binding reference to Message_string_ while the model was emitted as Message__string_.

This mirrors the same * stripping in nameTypeOf() and also deduplicates emitted models by generated TypeScript name so pointer and non-pointer generic instantiations do not produce duplicate class declarations after normalisation.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Windows
  • macOS
  • Linux

Commands run:

  • GOWORK=off go test ./internal/binding/binding_test -run TestGenericPointerBindingsUseSameTypeName
  • GOWORK=off go test ./internal/binding/...
  • GOWORK=off go test ./...
  • GOWORK=off go run ./cmd/wails doctor

I also attempted the repo-local coderabbit --plain check, but the coderabbit executable is not installed in this environment.

Test Configuration

# Wails
Version | v2.12.0

# System
OS           | MacOS
Version      | 26.3.1
ID           | 25D2128
Go Version   | go1.26.3
Platform     | darwin
Architecture | arm64
CPU          | Apple M4
Memory       | 16GB

# Dependencies
Xcode command line tools | Installed | 2416
Nodejs                   | Installed | 22.22.0
npm                      | Installed | 10.9.4

# Diagnosis
SUCCESS Your system is ready for Wails development!

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (v3 changelog entries are added automatically)
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Note: I used Codex while preparing this change, and I reviewed the final diff and ran the listed checks locally.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed incorrect TypeScript type naming for generic pointer bindings. Generated names now consistently match across binding declarations and model files, resolving type mismatches.
  • Tests

    • Added test suite validating generic pointer binding type name generation produces consistent results.
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3998d79b-3cf4-4e9b-998a-1bc74dd8b065

📥 Commits

Reviewing files that changed from the base of the PR and between 78cde81 and 15a2c83.

📒 Files selected for processing (4)
  • v2/internal/binding/binding_test/binding_generic_pointer_test.go
  • v2/internal/binding/binding_test/binding_generics_test.go
  • v2/internal/typescriptify/typescriptify.go
  • website/src/pages/changelog.mdx
💤 Files with no reviewable changes (1)
  • v2/internal/binding/binding_test/binding_generics_test.go

Walkthrough

Fixes a bug where Go generic pointer type arguments (e.g., Message[*string]) produced mismatched TypeScript names between App.d.ts (Message_string_) and models.ts (Message__string_). The fix strips * in nameTypeOf before name sanitization and adds an alreadyConvertedName map for entity-name-based deduplication in typescriptify.go. A new regression test and an updated existing test expectation are included.

Changes

Generic Pointer TypeScript Name Fix

Layer / File(s) Summary
nameTypeOf pointer stripping and alreadyConvertedName deduplication
v2/internal/typescriptify/typescriptify.go
nameTypeOf now strips * before processing generic brackets. TypeScriptify gains an alreadyConvertedName map initialized per Convert run, with early-return guards in convertEnum and convertType to prevent duplicate emission when types share a generated entity name.
Regression tests: new generic-pointer test and updated expectation
v2/internal/binding/binding_test/binding_generic_pointer_test.go, v2/internal/binding/binding_test/binding_generics_test.go
Adds TestGenericPointerBindingsUseSameTypeName with GenericPointerBindings/Message[T] fixtures that generate bindings and assert Message_string_ is used consistently. Updates the Generics2Test expected string to remove the extra leading underscore in the ListData_github_com_... class name.
Changelog
website/src/pages/changelog.mdx
Adds a bullet in the Unreleased/Fixed section for the TypeScript model name fix for generic pointer type arguments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • wailsapp/wails#3978: Addresses the same typescriptify.go generic type argument name sanitization code path, fixing similar TypeScript identifier generation issues for generics.

Suggested reviewers

  • leaanthony

Poem

🐇 A pointer named *string caused quite a fuss,
Two underscores crept in — suspicious, dubious!
I stripped the asterisk, added a name guard,
Now Message_string_ stands tall in the yard.
The models agree, no more TypeScript divide,
Hop hop hooray — consistency applied! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(v2): align generic pointer TypeScript names' directly and specifically describes the main change: aligning TypeScript type names for generic pointer types in the v2 binding generator.
Description check ✅ Passed The PR description includes issue reference (#5160), proper classification as a bug fix, detailed testing information (macOS, specific test commands), and confirms most checklist items including changelog update and test coverage.
Linked Issues check ✅ Passed The PR fully addresses issue #5160 by fixing the inconsistency between App.d.ts and models.ts type names for generic pointer types, adding a test case that validates the expected behavior, and implementing deduplication by TypeScript name.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the generic pointer TypeScript naming issue: test file addition, test expectation update, core typescriptify logic fix, and changelog entry.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"


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.

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

Labels

None yet

1 participant