-
Notifications
You must be signed in to change notification settings - Fork 533
Open
Description
As far as I understand, it is not possible to generate union types when generating a TS client library from a Go application. Here's an example:
Input
type Season string
const (
SeasonSummer Season = "Summer"
SeasonAutumn Season = "Autumn"
SeasonWinter Season = "Winter"
SeasonSpring Season = "Spring"
)
type SomeType struct {
Season Season `json:"season"`
}Expected output
export interface SomeType {
season: "Summer" | "Autumn" | "Winter" | "Spring"
}Actual output
export interface SomeType {
season: string
}I.e. in order to strongly type season in my TypeScript application (as in my Go API), I would need to write a custom union type and hence maintain it both in TS and Go which defeats the purpose of generating a type for this example. Ideally, the generated TS type would be a union type but a TS enum would also be OK:
enum Season {
SeasonSummer Season = "Summer"
SeasonAutumn Season = "Autumn"
SeasonWinter Season = "Winter"
SeasonSpring Season = "Spring"
}Thanks in advance!
Thlamz
Metadata
Metadata
Assignees
Labels
No labels