Allow renaming of primitive types - #4
Open
laknoll wants to merge 9 commits into
Open
Conversation
TypeScript doesn't like fields in interfaces containing a hyphen unless they are quoted. So check for that and add quotes around the name in this case.
Go 1.24 added the omitzero struct tag option, and the new json encoder in Go 1.27 uses it as well. Like omitempty it makes the field absent from the JSON output, so mark such members optional in TypeScript. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Upgrade the test dependencies (repr v0.5.4, go-test/deep v1.1.1) and replace the single strcase call in the default type namer with a local upperFirst helper. strcase v0.3.0 changed ToCamel to lower-case the tail of acronyms, which would have renamed generated types like HTTPServer to Httpserver and ID to Id. upperFirst only upper-cases the first rune, which is all the default namer ever needed for a Go type name, and it no longer drops leading non-ASCII runes the way old strcase did. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The strcase removal in v1.2.0 dropped more than the acronym mangling it was meant to avoid: old strcase.ToCamel also deleted every rune outside [A-Za-z0-9]. That mattered for instantiated generics, whose reflect name carries the type arguments, so Pair[string,int] started rendering as "export interface Pair[string,int]" -- not valid TypeScript. Drop runes TypeScript does not allow in an identifier before upper-casing the first one, which restores Pairstringint. Underscores and non-ASCII letters are legal in a TypeScript identifier and are now kept rather than dropped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows renaming primitive types. This is helpful if those types are marshalled in a non standard way.
In our case, we had a
type Timestamp int64that we are marshalling as a string. With this change, it’s possible to customise the generated typescript type for non struct types as well.