RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.37k stars 529 forks source link

TypeScript generator: Use string type as the discriminator property type in specialized interfaces #1718

Closed RicoSuter closed 1 month ago

RicoSuter commented 1 month ago

New

export interface Base {
    Type: EBase;
}

export type EBase = "OneChild" | "SecondChild";

export interface OneChild extends Base {
    A: string;
    Type: 'OneChild';
}

export interface SecondChild extends Base {
    B: string;
    Type: 'SecondChild';
}

export interface MyClass {
    Child: Base;
    Children: Base[];
}

Before

export interface Base {
    Type: EBase;
}

export type EBase = "OneChild" | "SecondChild";

export interface OneChild extends Base {
    A: string;
    Type: EBase;
}

export interface SecondChild extends Base {
    B: string;
    Type: EBase;
}

export interface MyClass {
    Child: Base;
    Children: Base[];
}