Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript-generator-maven-plugin v3.2.1263 generates invalid TypeScript files (interfaces extending union types) #1058

Open
emirant1 opened this issue Apr 18, 2024 · 0 comments

Comments

@emirant1
Copy link

Hello everyone
First of all I would like to thank you big time for your plugin, overall it works really well and it spares us a lot of time.
It seems like its behaviour has changed (possible regression) since the last version. In our context it generates interfaces that are not valid. Let me explain by providing an example.

Consider the following Java Objects:

@SuperBuilder
@Data
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class TransportType {
    private String transportId;
}
@SuperBuilder
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = true)
public class Boat extends TransportType {
    private String boatSpecificProperty;
}
@SuperBuilder
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = true)
public class Plane extends TransportType {
    private String planeSpecificProperty;
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
        @JsonSubTypes.Type(value = Courier.class, name = "COURIER"),
        @JsonSubTypes.Type(value = Freight.class, name = "FREIGHT")
})
@SuperBuilder
@Data
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class Shipment<T extends TransportType> implements Serializable {
    private String id;
}
@SuperBuilder
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = true)
public class Courier extends Shipment<Plane> {
    private String courierSpecificProperty;
}
@SuperBuilder
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = true)
public class Freight extends Shipment<Boat> {
    String freightSpecificProperty;
}

The generated TypeScript according to their respective version

v3.1.1185

export interface TransportType {
    transportId: string;
}

export interface Boat extends TransportType {
    boatSpecificProperty: string;
}

export interface Plane extends TransportType {
    planeSpecificProperty: string;
}

export interface Shipment<T> extends Serializable {
    type: "COURIER" | "FREIGHT";
    id: string;
}

export interface Courier extends Shipment<Plane> {
    type: "COURIER";
    courierSpecificProperty: string;
}

export interface Freight extends Shipment<Boat> {
    type: "FREIGHT";
    freightSpecificProperty: string;
}

v3.2.1263

export interface TransportType {
    transportId: string;
}

export interface Boat extends TransportType {
    boatSpecificProperty: string;
}

export interface Plane extends TransportType {
    planeSpecificProperty: string;
}

export interface Shipment<T> extends Serializable {
    type: "COURIER" | "FREIGHT";
    id: string;
}

export type ShipmentUnion<T> = Courier | Freight;

export interface Courier extends ShipmentUnion<Plane> {
    type: "COURIER";
    courierSpecificProperty: string;
}

export interface Freight extends ShipmentUnion<Boat> {
    type: "FREIGHT";
    freightSpecificProperty: string;
}

This results, in the latest version, to the following error message:
TS2312: An interface can only extend an object type or intersection of object types with statically known members.

Which prevents our software from working properly.

Many thanks in advance for your answer.

Greetings

Antoine

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

No branches or pull requests

1 participant