gzuidhof / tygo

Generate Typescript types from Golang source code
MIT License
597 stars 40 forks source link

Generic type with `any` in Golang not working #65

Closed KiddoV closed 6 days ago

KiddoV commented 1 month ago

I have:

//Go
type FeEnum[T any] struct {
    Value  T
    TSName string
}

After generate I got:

//TypeScript
export interface FeEnum<T extends > { //<=== missing `any` here!!!!
  Value: T;
  TSName: string;
}
spywiree-priv commented 1 week ago

Here is another example:

Go input:

type JsonArray[T any] []T

func (a JsonArray[T]) MarshalJSON() ([]byte, error) {
    if a == nil {
        return []byte("[]"), nil
    }
    return json.MarshalNoEscape([]T(a))
}

TS output:

export type JsonArray = T[];

Should be:

export type JsonArray<T> = T[];
gzuidhof commented 6 days ago

This should be fixed with #69 in version 0.2.16.