gzuidhof/tygo

Unwrapping / extending inline structs

lxnre-codes opened this issue · 3 comments

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).

@gzuidhof made a PR for this #30 .

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