Skip to content

Allow renaming of primitive types - #4

Open
laknoll wants to merge 9 commits into
csweichel:masterfrom
laknoll:master
Open

Allow renaming of primitive types#4
laknoll wants to merge 9 commits into
csweichel:masterfrom
laknoll:master

Conversation

@laknoll

@laknoll laknoll commented Oct 17, 2022

Copy link
Copy Markdown

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 int64
that we are marshalling as a string. With this change, it’s possible to customise the generated typescript type for non struct types as well.

laknoll and others added 9 commits October 17, 2022 13:15
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant