-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to emit literal Typescript from with Go file #52
Conversation
This solves the problem of a struct field being marshalled into a tuple. It could also be acheived by putting frontmatter into tygo.yaml, but that separates the TS definition from the type. Ideally we would like to say `tstype:"[a:number, b:number,c:string]"` in the field tag, but commas are inescapably reserved for tag delimiters.
This allows multi-line content more easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
This is a great contribution :)
return false | ||
} | ||
isEmit := false | ||
if x.Tok == token.VAR { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this makes sense to support token.CONST
too? (or perhaps there is a good reason not to?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consts are already handled to export the const definition itself, so I'm inclined to not handle them here as it makes it more complex it we have to decide which way to handle it.
Co-authored-by: Guido Zuidhof <[email protected]>
Let me know when you are happy for me to merge this |
I'm happy if you are happy with not handling |
This implements a feature to allow a Go file to contain Typescript definitions that can't be expressed through
tstype
tags.There are actually two ways of doing it implemented. I think both have their uses but perhaps only one should be included, in which case I would say the var string literal one should be preferred.
Motivating Example:
We have a struct that is marshalled into JSON, and therefore exposed to TS, as a tuple of values, to minimise size on the wire. (it saves about 30% after gzip compression)
Prior art:
There are of course already ways to handle this.
frontmatter
in the configuration, but I think this separates the TS declaration from the Go too much.I hope you find this change acceptable and thanks for reading.