Skip to content
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
11 changes: 11 additions & 0 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ func (ts *Typescript) parse(obj types.Object) error {
switch obj := obj.(type) {
// All named types are type declarations
case *types.TypeName:
// Check for any custom overrides before processing any named types.
if custom, ok := ts.parsed.typeOverrides[obj.Type().String()]; ok {
return ts.setNode(objectIdentifier.Ref(), typescriptNode{
Node: &bindings.Alias{
Name: objectIdentifier,
Type: custom(),
Source: ts.location(obj),
},
})
}

var rhs types.Type
switch typedObj := obj.Type().(type) {
case *types.Named:
Expand Down
5 changes: 5 additions & 0 deletions convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func TestGeneration(t *testing.T) {
case "testdata/excludecustom":
err = gen.ExcludeCustom("github.com/coder/guts/testdata/excludecustom.Secret")
require.NoErrorf(t, err, "exclude %q", dir)
case "testdata/alias":
err = gen.IncludeCustom(map[guts.GolangType]guts.GolangType{
"github.com/coder/guts/testdata/alias.RemappedAlias": "string",
})
require.NoError(t, err)
}

gen.IncludeCustomDeclaration(config.StandardMappings())
Expand Down
3 changes: 3 additions & 0 deletions testdata/alias/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ type AliasStruct = FooStruct
type AliasStructNested = AliasStruct
type AliasStructSlice = []FooStruct
type AliasStructNestedSlice = []AliasStructNested

// RemappedAlias should be manually remapped to "string" in the test settings.
type RemappedAlias = FooStruct
3 changes: 3 additions & 0 deletions testdata/alias/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ export type Foo = string;
export interface FooStruct {
readonly Key: string;
}

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