Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: rename SimplifyOmitEmpty to SimplifyOptional #28

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

Merged
merged 1 commit into from
May 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions config/mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
"github.com/coder/guts/bindings/walk"
)

// SimplifyOmitEmpty removes the null type from union types that have a question token.
// This is because if 'omitempty' is set, then golang will omit the object key,
// rather than sending a null value to the client.
// SimplifyOptional removes the null type from union types that have a question
// token. This is because if 'omitempty' or 'omitzero' is set, then golang will
// omit the object key, rather than sending a null value to the client.
//
// Example:
// number?: number | null --> number?: number
func SimplifyOmitEmpty(ts *guts.Typescript) {
func SimplifyOptional(ts *guts.Typescript) {
ts.ForEach(func(key string, node bindings.Node) {
switch node := node.(type) {
case *bindings.Interface:
Expand All @@ -37,6 +38,14 @@ func SimplifyOmitEmpty(ts *guts.Typescript) {
})
}

// SimplifyOmitEmpty is a deprecated alias for SimplifyOptional.
// It was implemented for the `omitempty` case, however it's usage affects
// 'omitzero' as well.
// Deprecated: Use SimplifyOptional instead.
func SimplifyOmitEmpty(ts *guts.Typescript) {
SimplifyOptional(ts)
}

// ExportTypes adds 'export' to all top level types.
// interface Foo {} --> export interface Foo{}
func ExportTypes(ts *guts.Typescript) {
Expand Down