Skip to content

Conversation

@webjunkie
Copy link

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

@domoritz domoritz marked this pull request as draft April 7, 2024 22:57
When using `*` to generate schemas for all types, discriminated unions
referenced from within their member types would fail with "multiple
definitions" error. The same type appeared with different annotation
hashes depending on context (with @Discriminator vs without).

Compare base type IDs (stripped of AnnotatedType wrapper) to detect
when apparent duplicates are actually the same underlying type with
different annotations.
@webjunkie webjunkie marked this pull request as ready for review November 26, 2025 09:39
@domoritz
Copy link
Member

domoritz commented Dec 2, 2025

@arthurfiorette can you take a look?

Copy link
Collaborator

@arthurfiorette arthurfiorette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl makes sense ihmo. Needs to fix lint issues before merging

@arthurfiorette arthurfiorette self-assigned this Dec 3, 2025
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

Successfully merging this pull request may close these issues.

3 participants