Skip to content

De-duplicate unions. #1069

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

Merged

Conversation

mitchell-merry
Copy link
Contributor

Changes

If a union has multiple members that are the same, then we should de-duplicate them.

#1049 (comment)

How to Review

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (if applicable)

@mitchell-merry mitchell-merry marked this pull request as ready for review April 6, 2023 23:55
@@ -91489,7 +91489,7 @@ export interface operations {
/** @description The [status](https://docs.github.com/rest/commits/statuses) contexts to verify against commit status checks. If you omit this parameter, GitHub verifies all unique contexts before creating a deployment. To bypass checking entirely, pass an empty array. Defaults to all unique contexts. */
required_contexts?: (string)[];
payload?: OneOf<[{
[key: string]: unknown | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is pretty nice

@mitchell-merry
Copy link
Contributor Author

mitchell-merry commented Apr 7, 2023

Hm, I think this happens to fix #810 as well.

Currently, a schema like this:

    MetaQuote:
      oneOf: []
      discriminator:
        propertyName: meta_serialization_key
        mapping: {}

generates like so:

export interface components {
  schemas: {
    MetaQuote: ; // error here
  };
}

Now, we default to never when no types are passed into tsUnionOf, so we get:

export interface components {
  schemas: {
    MetaQuote: never;
  };
}

which I believe is what we expect, right? I can add a more specific regression test for this if we want.

const members = new Set<string>();
for (const t of types) {
// unknown swallows everything else in the union
if (t === "unknown") return "unknown";
Copy link
Contributor

Choose a reason for hiding this comment

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

ah this is smart! I hadn’t considered this ❤️

}

// never gets swallowed by anything else, so only return never
// if it is the only member
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@drwpow
Copy link
Contributor

drwpow commented Apr 7, 2023

Really appreciate all your awesome work on this library, and your helpfulness in the issues! I accept your offer to help and have invited you to have maintaner access 🙂. PRs still require approval from another maintainer, but you can at least open PRs and triage issues easier now. Thank you so much! 🙏

@drwpow
Copy link
Contributor

drwpow commented Apr 7, 2023

When you get accept access to this project, I’ll let you merge this one 🙂

@mitchell-merry mitchell-merry force-pushed the mitchell-merry/dedupe-unions branch from 0045587 to 80fa7af Compare April 9, 2023 22:47
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.

2 participants