vojtechhabarta / typescript-generator

Generates TypeScript from Java - JSON declarations, REST service client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#936 breaks code generation for generic parent classes

fwiesweg opened this issue · comments

First of all, thanks for all the good work, I think I already said it once but your library is and remains incredibly helpful!

#936 (commit d41d22f) seems to have broken code generation for classes with generic parents for me. I attached simplified samples of the issue below. The actual code is quite a bit more complicated, so in case you cannot reproduce it with these, please let me know so I can cook up something more complete.

Java:

@JsonSubTypes({
        @JsonSubTypes.Type(value = ClientPaymentSystem.class),
        @JsonSubTypes.Type(value = InternalPaymentSystem.class)
})
public abstract class PaymentSystem<CONF extends PaymentSystemConfig>{
}

public class InternalPaymentSystem extends PaymentSystem<VoidPaymentSystemConfig> {
   ...
}

Without #936:

export type PaymentSystemUnion<CONF> = ClientPaymentSystem | InternalPaymentSystem | ...
export interface PaymentSystem<CONF> extends CMDomainBaseModel, CMDomainEntitySubject {
    config: CONF;
    type: 'ClientPaymentSystem' | 'InternalPaymentSystem' | ....
}

export interface InternalPaymentSystem extends PaymentSystem<VoidPaymentSystemConfig> {
    active?: boolean | null;
    config: VoidPaymentSystemConfig;
    type: 'InternalPaymentSystem';
}

With #936:

export type PaymentSystemUnion<CONF> = ClientPaymentSystem | InternalPaymentSystem | ...
export interface PaymentSystem<CONF> extends CMDomainBaseModel, CMDomainEntitySubject {
    config: CONF;
    type: 'ClientPaymentSystem' | 'InternalPaymentSystem' | ....
}

// changed after extends
export interface InternalPaymentSystem extends PaymentSystemUnion<VoidPaymentSystemConfig> {
    active?: boolean | null;
    config: VoidPaymentSystemConfig;
    type: 'InternalPaymentSystem';
}

which does not compile with ts 4.7.4 (yes I know it's a bit dated...), claiming that inheritance is not possible because not all fields of the PaymentSystemUnion are known, contrary to those of PaymentSystem

I have read the commit message and code, but it's been a while since I've done a deep dive into your code and am not quite sure what the intention of this change is, so I'm hesitant to propose a half-baked fix in a pull request and would not mind some pointers if you have any.