-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Opt-in nullable slices #4920
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
base: master
Are you sure you want to change the base?
Opt-in nullable slices #4920
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
v2/internal/typescriptify/typescriptify.go (1)
281-344: AddMapField missing nullable suffix for slice value types.When
useNullableSlicesis enabled,AddMapFielddoesn't apply the nullable suffix to slice value types. Compare lines 291-301 (where slice values are handled) withAddArrayOfStructsField(lines 949-956) andAddSliceField(lines 873-878)—both correctly applynullableSuffix = " | null"whent.useNullableSlicesis true. Map fields with slice values (e.g.,map[string][]int,map[string][][]int) generateRecord<string, Array<...>>instead ofRecord<string, Array<...> | null>, inconsistent with direct slice field handling. This affects test cases like those inbinding_deepelements_test.go(lines 17-30).
🤖 Fix all issues with AI agents
In `@website/src/pages/changelog.mdx`:
- Line 36: The changelog line mentioning the `nullableSlices` opt-in currently
placed under v2.11.0 should be moved to the "Unreleased → Added" section unless
this was intentionally backported; verify whether this PR (the `nullableSlices`
entry referencing `#4920`) is a backport, and if not, cut the line "Added
`nullableSlices` opt-in to allow nullable array type generation in
[`#4920`](https://github.com/wailsapp/wails/pull/4920)" from its current v2.11.0
location in website/src/pages/changelog.mdx and paste it under the Unreleased →
Added subsection so the entry appears in the correct release section.
🧹 Nitpick comments (2)
v2/internal/typescriptify/typescriptify.go (1)
874-878: Consider extracting duplicated nullable suffix logic.The nullable suffix construction (
" | null") is duplicated in bothAddSimpleArrayFieldandAddArrayOfStructsField. Consider extracting this into a helper method for consistency and maintainability.♻️ Suggested refactor
// Add helper method to typeScriptClassBuilder func (t *typeScriptClassBuilder) nullableSuffix() string { if t.useNullableSlices { return " | null" } return "" }Then use
t.nullableSuffix()in both methods.Also applies to: 951-955
v2/internal/binding/generate_test.go (1)
153-184: Good test coverage for nullable slices.The test correctly validates:
[]int→Array<number> | null[]bool→Array<boolean> | null[]byte→string(special case preserved)Consider adding test cases for nested arrays (e.g.,
[][]int) and maps with slice values to ensure complete coverage.💡 Additional test cases to consider
{ name: "nested slice nullable", input: "[][]int", want: "Array<Array<number> | null> | null", // verify expected behavior }, { name: "map with slice value nullable", input: "map[string][]int", want: "Record<string, Array<number> | null>", // verify expected behavior },
|
|
||
| ### Added | ||
|
|
||
| - Added `nullableSlices` opt-in to allow nullable array type generation in [#4920](https://github.com/wailsapp/wails/pull/4920) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this entry to “Unreleased → Added” unless it’s a backport.
This PR was opened on January 28, 2026, while v2.11.0 is dated November 8, 2025, so the changelog entry likely belongs under the Unreleased “Added” section. Please confirm if this is intentionally backported to v2.11.0; otherwise, relocate it.
📌 Suggested edit (if not a backport)
## [Unreleased]
+### Added
+
+- Added `nullableSlices` opt-in to allow nullable array type generation in [`#4920`](https://github.com/wailsapp/wails/pull/4920)
+
### Fixed
@@
-### Added
-
-- Added `nullableSlices` opt-in to allow nullable array type generation in [`#4920`](https://github.com/wailsapp/wails/pull/4920)🤖 Prompt for AI Agents
In `@website/src/pages/changelog.mdx` at line 36, The changelog line mentioning
the `nullableSlices` opt-in currently placed under v2.11.0 should be moved to
the "Unreleased → Added" section unless this was intentionally backported;
verify whether this PR (the `nullableSlices` entry referencing `#4920`) is a
backport, and if not, cut the line "Added `nullableSlices` opt-in to allow
nullable array type generation in
[`#4920`](https://github.com/wailsapp/wails/pull/4920)" from its current v2.11.0
location in website/src/pages/changelog.mdx and paste it under the Unreleased →
Added subsection so the entry appears in the correct release section.



Description
Adds an opt-in flag to enable null type generation for slices. On
masterif you haveGenerates
Since slices are default
nilin golang makes sense that the binding generation would be able to support nullable vs undefined (which is currently covered withfieldName?onomitemptyThis could cause breaking changes if set as default behavior due to typescript error on null checks, so I made it opt in via wails.json
It will then output
Fixes # (issue)
Issues reported in discord community/direct
Type of change
Please select the option that is relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using
wails doctor.If you checked Linux, please specify the distro and version.
Test Configuration
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.