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

Skip to content

fix: alias fields in structs #25

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 13, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,9 @@ func (ts *Typescript) typescriptType(ty types.Type) (parsedType, error) {
},
}, nil
case *types.Alias:
// TODO: Verify this is correct.
return ts.typescriptType(ty.Underlying())
// See https://github.com/golang/go/issues/66559
// Rhs will traverse all aliasing types until it finds the base type.
return ts.typescriptType(ty.Rhs())
case *types.Union:
allTypes := make([]bindings.ExpressionType, 0, ty.Len())
for i := 0; i < ty.Len(); i++ {
Expand Down
9 changes: 9 additions & 0 deletions testdata/alias/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ type AliasNested = Alias
type Alias = Foo
type AliasString = string
type AliasStringSlice = []string

type FooStruct struct {
Key string
}

type AliasStruct = FooStruct
type AliasStructNested = AliasStruct
type AliasStructSlice = []FooStruct
type AliasStructNestedSlice = []AliasStructNested
21 changes: 21 additions & 0 deletions testdata/alias/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,26 @@ export type AliasString = string;
// From alias/alias.go
export type AliasStringSlice = readonly string[];

// From alias/alias.go
export interface AliasStruct {
readonly Key: string;
}

// From alias/alias.go
export interface AliasStructNested {
readonly Key: string;
}

// From alias/alias.go
export type AliasStructNestedSlice = readonly FooStruct[];

// From alias/alias.go
export type AliasStructSlice = readonly FooStruct[];

// From alias/alias.go
export type Foo = string;

// From alias/alias.go
export interface FooStruct {
readonly Key: string;
}