diff --git a/convert.go b/convert.go index 2e74955..abf15cd 100644 --- a/convert.go +++ b/convert.go @@ -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++ { diff --git a/testdata/alias/alias.go b/testdata/alias/alias.go index 52a8368..58b7ecd 100644 --- a/testdata/alias/alias.go +++ b/testdata/alias/alias.go @@ -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 diff --git a/testdata/alias/alias.ts b/testdata/alias/alias.ts index e097f7f..a1aeee5 100644 --- a/testdata/alias/alias.ts +++ b/testdata/alias/alias.ts @@ -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; +}