From 85e588a5c6e2d0c151908e9d9e64ee5d6bd3f34e Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Sun, 18 Jan 2026 18:16:08 -0600 Subject: [PATCH 1/2] fix: use alias override in struct type --- convert.go | 7 +++++++ testdata/alias/alias.go | 4 ++++ testdata/alias/alias.ts | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/convert.go b/convert.go index 8d9c128..cbda5a6 100644 --- a/convert.go +++ b/convert.go @@ -1129,6 +1129,13 @@ func (ts *Typescript) typescriptType(ty types.Type) (parsedType, error) { }, }, nil case *types.Alias: + custom, ok := ts.parsed.typeOverrides[ty.String()] + if ok { + return parsedType{ + Value: custom(), + }, nil + } + // 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()) diff --git a/testdata/alias/alias.go b/testdata/alias/alias.go index d218ec6..e276854 100644 --- a/testdata/alias/alias.go +++ b/testdata/alias/alias.go @@ -18,3 +18,7 @@ type AliasStructNestedSlice = []AliasStructNested // RemappedAlias should be manually remapped to "string" in the test settings. type RemappedAlias = FooStruct + +type UseAliasedType struct { + Field1 RemappedAlias +} diff --git a/testdata/alias/alias.ts b/testdata/alias/alias.ts index 78a482a..70caf68 100644 --- a/testdata/alias/alias.ts +++ b/testdata/alias/alias.ts @@ -38,3 +38,8 @@ export interface FooStruct { // From alias/alias.go export type RemappedAlias = string; + +// From alias/alias.go +export interface UseAliasedType { + readonly Field1: string; +} From ae4477fb7822b136c13d87a1e93eb6166de9220d Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 21 Jan 2026 10:14:12 -0600 Subject: [PATCH 2/2] chore: custom override types should work in all usage Was previously hard coded to only certain situations. --- convert.go | 15 ++++++++------- testdata/alias/alias.go | 10 ++++++++-- testdata/alias/alias.ts | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/convert.go b/convert.go index cbda5a6..e2eea0d 100644 --- a/convert.go +++ b/convert.go @@ -870,6 +870,14 @@ func (p parsedType) WithComments(comments ...string) parsedType { // TODO: Return comments? func (ts *Typescript) typescriptType(ty types.Type) (parsedType, error) { + // No matter what the type is, if we have some custom override, always use that. + custom, ok := ts.parsed.typeOverrides[ty.String()] + if ok { + return parsedType{ + Value: custom(), + }, nil + } + switch ty := ty.(type) { case *types.Signature: // TODO: Handle functions better @@ -1129,13 +1137,6 @@ func (ts *Typescript) typescriptType(ty types.Type) (parsedType, error) { }, }, nil case *types.Alias: - custom, ok := ts.parsed.typeOverrides[ty.String()] - if ok { - return parsedType{ - Value: custom(), - }, nil - } - // 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()) diff --git a/testdata/alias/alias.go b/testdata/alias/alias.go index e276854..da948ca 100644 --- a/testdata/alias/alias.go +++ b/testdata/alias/alias.go @@ -19,6 +19,12 @@ type AliasStructNestedSlice = []AliasStructNested // RemappedAlias should be manually remapped to "string" in the test settings. type RemappedAlias = FooStruct -type UseAliasedType struct { - Field1 RemappedAlias +type UseAliasedType[G any] struct { + Field RemappedAlias + AsKey map[RemappedAlias]string + AsVal map[string]RemappedAlias + AsSlice []RemappedAlias + AsGeneric G } + +type GenericUseRemappedAlias = UseAliasedType[RemappedAlias] diff --git a/testdata/alias/alias.ts b/testdata/alias/alias.ts index 70caf68..f7fd12e 100644 --- a/testdata/alias/alias.ts +++ b/testdata/alias/alias.ts @@ -36,10 +36,23 @@ export interface FooStruct { readonly Key: string; } +// From alias/alias.go +export interface GenericUseRemappedAlias { + readonly Field: string; + readonly AsKey: Record | null; + readonly AsVal: Record | null; + readonly AsSlice: readonly string[]; + readonly AsGeneric: string; +} + // From alias/alias.go export type RemappedAlias = string; // From alias/alias.go -export interface UseAliasedType { - readonly Field1: string; +export interface UseAliasedType { + readonly Field: string; + readonly AsKey: Record | null; + readonly AsVal: Record | null; + readonly AsSlice: readonly string[]; + readonly AsGeneric: G; }