Skip to content

Commit 437443f

Browse files
authored
fix: alias fields in structs (#25)
1 parent ad36901 commit 437443f

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

convert.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,9 @@ func (ts *Typescript) typescriptType(ty types.Type) (parsedType, error) {
10041004
},
10051005
}, nil
10061006
case *types.Alias:
1007-
// TODO: Verify this is correct.
1008-
return ts.typescriptType(ty.Underlying())
1007+
// See https://github.com/golang/go/issues/66559
1008+
// Rhs will traverse all aliasing types until it finds the base type.
1009+
return ts.typescriptType(ty.Rhs())
10091010
case *types.Union:
10101011
allTypes := make([]bindings.ExpressionType, 0, ty.Len())
10111012
for i := 0; i < ty.Len(); i++ {

testdata/alias/alias.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ type AliasNested = Alias
66
type Alias = Foo
77
type AliasString = string
88
type AliasStringSlice = []string
9+
10+
type FooStruct struct {
11+
Key string
12+
}
13+
14+
type AliasStruct = FooStruct
15+
type AliasStructNested = AliasStruct
16+
type AliasStructSlice = []FooStruct
17+
type AliasStructNestedSlice = []AliasStructNested

testdata/alias/alias.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,26 @@ export type AliasString = string;
1212
// From alias/alias.go
1313
export type AliasStringSlice = readonly string[];
1414

15+
// From alias/alias.go
16+
export interface AliasStruct {
17+
readonly Key: string;
18+
}
19+
20+
// From alias/alias.go
21+
export interface AliasStructNested {
22+
readonly Key: string;
23+
}
24+
25+
// From alias/alias.go
26+
export type AliasStructNestedSlice = readonly FooStruct[];
27+
28+
// From alias/alias.go
29+
export type AliasStructSlice = readonly FooStruct[];
30+
1531
// From alias/alias.go
1632
export type Foo = string;
33+
34+
// From alias/alias.go
35+
export interface FooStruct {
36+
readonly Key: string;
37+
}

0 commit comments

Comments
 (0)