Skip to content

Implement discriminated union schema - #15

Merged
lazamar merged 6 commits into
mainfrom
union
Nov 26, 2025
Merged

Implement discriminated union schema#15
lazamar merged 6 commits into
mainfrom
union

Conversation

@lazamar

@lazamar lazamar commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

Better way to specify schemas for discriminated unions than using oneOf.

const schema = discriminatedUnion([
  variant({ ty: 'one', a: string }),
  variant({ ty: 'two', b: number }),
]);

type Ty = Infer<typeof schema>;

/* inferred type:
type Ty = {
    readonly ty: "one";
    readonly a: string;
} | {
    readonly ty: "two";
    readonly b: number;
}
*/

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@tjschutte

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ambar-core/src/json/schema.ts Outdated

@EthanRBrown EthanRBrown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a definite improvement, thank you! Couple of minor notes, but approved

Comment thread ambar-core/src/json/schema.ts Outdated
Comment thread ambar-core/tests/suites/json.ts
@lazamar
lazamar merged commit c1e54a5 into main Nov 26, 2025
1 check passed
@ctuncay
ctuncay deleted the union branch January 29, 2026 10:58
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