Skip to content

bug: generating embedded types doesn't conform to the json package #87

@empijei

Description

@empijei

The encoding/json package states:

Embedded struct fields are usually marshaled as if their inner exported fields were fields in the outer struct, subject to the usual Go visibility rules amended as described in the next paragraph. An anonymous struct field with a name given in its JSON tag is treated as having that name, rather than being anonymous. An anonymous struct field of interface type is treated the same as having that type as its name, rather than being anonymous.

Which means that the following code

type A struct {
  A string
}

type B struct {
 A
 Foo string
}

Should be converted to

export interface A {
 A: string;
}

export interface B extends A { // This implies there is a `A: string` field
 Foo string;
}

But it is instead converted into

export interface B {
 Foo string;
 A: A;
}

This means that the generated typescript cannot deal with embedded types correctly.

Edit: I see now that tstype:",extends"exists, I just reckon it should be the default or there should be a way to make it the default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions