tkrajina/typescriptify-golang-structs

64-bit integer as string

kulak opened this issue · 3 comments

kulak commented

Hi,

So, I am using project to generate TypeScript structures for Protocol Buffers generated GO structures. It works.

But, I am using int64 in Prtocol Buffers, which correctly serialize as Strings, because JavaScript Number is not large enough for int64. So, the workaround is to serialize int64 to string.

That means that this library would have to adjust for this specific scenario to generate string instead of Number.

I have made a change to suite me in my fork, but I really would like to push it over time into this project. so, I am opening this issue to discuss the most desired solution.

Mine is pretty straightforward: kulak@5421143 Unfortunately, I have changed the package name to mine to be able to work with the package today. So, I cannot make Pull Request without cleanup.

Thank you

Hi @kulak, if all you need is to have field: string for int64 fields, can't you achieve the same thing with ts_type tags:

type Something struct {
    Number int64 `json:"number" ts_type:"string"`
}

The only problem is that you have to do that for every int64 field.

Anyway, that's not to say that I'm against your solution. Feel free to send a PR, I'll clean the package name collision.

kulak commented

Thank you. I did not know that.

The code is running against protocol buffers generated GO code. So, I don't really have control over tags in there. Well, there are ways to pass tags, but it is a lot of work.

kulak commented

I want do a PR, but it is not a priority at the moment for me. So, it might take some time.