gzuidhof / tygo

Generate Typescript types from Golang source code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unwrapping / extending inline structs

lxnre-codes opened this issue · comments

commented

Structs that are tagged as inline should be unwrapped.

// Input
type Vehicle struct {
	Category string `json:"category"`
	Make     string `json:"make"`
}

type Toyota struct {
	Vehicle `    json:",inline" tstype:",inline"`
	Year    int `json:"year"`
}
//Output
interface Vehicle {
  category: string;
  make: string;
}

interface Toyota extends Vehicle {
  year: number;
}

//Or 
interface Toyota  {
  category: string;
  make: string;
  year: number;
}

I think this is the same underlying challenge as in #15. It can definitely be done, but the current tygo transpiler is single pass, which makes this tricky (if not impossible).

commented

@gzuidhof made a PR for this #30 .

Shipped with #30, thank you @0x-buidl