Skip to content

feat: add explicit fallback variants for discriminated union - #349

Open
nyaomaru wants to merge 12 commits into
mainfrom
discriminated-union-fallback
Open

nyaomaru wants to merge 12 commits into
mainfrom
discriminated-union-fallback

Conversation

@nyaomaru

Copy link
Copy Markdown
Owner

Summary

Add explicit fallback variants for discriminated union.

Description

Adds discriminatedUnionWithFallback<T>(), a decoder-style companion to discriminatedUnion.

  • Keeps known discriminant branches exhaustive and validated by their existing guards.
  • Converts undeclared own primitive discriminants into one explicit canonical fallback variant.
  • Returns ParseResult, making transformed fallback output distinct from a guard result.
  • Allows the fallback factory to reject an unknown discriminant with undefined.

@vercel

vercel Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
is-kit-docs Ready Ready Preview Oct 17, 2026 4:21pm UTC

Request Review

@nyaomaru
nyaomaru marked this pull request as ready for review October 17, 2026 11:44
@nyaomaru

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T16:34:02.309139Z 815b72d Manual 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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.

Reviewed commit: 3682c68338

ℹ️ 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 src/core/combinators/discriminated-union.ts Outdated
@nyaomaru

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 14cc06d925

ℹ️ 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".

@nyaomaru

Copy link
Copy Markdown
Owner Author

@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.

Reviewed commit: 815b72da2b

ℹ️ 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 on lines +441 to +442
if (fallbackData === undefined || !isPlainObject(fallbackData)) {
return { valid: false };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject prototype-backed fallback fields

When fallback.create returns an object whose custom prototype has a null prototype and supplies a typed field—for example, Object.create(Object.assign(Object.create(null), { message: 'x' })) as { message: string }—isPlainObject accepts it, but createFallbackVariant copies only the payload's own keys. The decoder therefore reports success with no message property even though its return type exposes message: string. This is fresh evidence beyond the prior non-enumerable-own-property case: reject accepted payloads with custom prototypes or otherwise preserve the inherited fields represented by the payload type.

Useful? React with 👍 / 👎.

This branch was successfully deployed

1 active deployment
Preview — 815b72da Deployed Oct 17, 2026 by vercel[bot]
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.

1 participant