ts-json-schema-generator icon indicating copy to clipboard operation
ts-json-schema-generator copied to clipboard

Error "has multiple definitions" with discriminate unions

Open webjunkie opened this issue 1 year ago • 0 comments

I encounter errors with using discriminate unions in certain cases. I was able to reproduce a test case that throws Type "Animal" has multiple definitions.

Interestingly, if I modify the example and add just another type and make that the discriminate union, it works, but it would be very inconvenient in my project:

export type Fish = {
    animal_type: "fish";
    found_in: "ocean" | "river";
};

export type Bird = {
    animal_type: "bird";
    can_fly: boolean;
    likes_to_eat: EatSource;
};

export type Animal = Bird | Fish;

/**
 * @discriminator animal_type
 */
export type EatSource = Animal

webjunkie avatar Dec 20 '23 15:12 webjunkie