Flatten single-variant choice types and optional slice auto-fields - #95
Merged
Conversation
ryukzak
force-pushed
the
feat/flatten-choice-types
branch
from
March 4, 2026 16:25
324a872 to
abf69a5
Compare
When a slice constrains a polymorphic field (e.g. value[x]) to exactly
one variant (e.g. valueQuantity), the slice API now promotes that
variant's fields directly. Users write `{ value: 120, unit: "mmHg" }`
instead of `{ valueQuantity: { value: 120, unit: "mmHg" } }`.
- Add `elements` to FieldSlice type and propagate from field-builder
- Detect constrained choices by resolving base type's ChoiceFieldDeclaration
- Generate flattened input types (Omit all choice variants & intersect)
- Add wrapSliceChoice/flattenSliceChoice runtime helpers
Fields like category and component that have required slices were previously hardcoded auto-fields. Now they're optional params in create() — if the user provides their own values, required slice stubs are auto-merged when missing instead of being overwritten.
ryukzak
force-pushed
the
feat/flatten-choice-types
branch
from
March 4, 2026 16:29
abf69a5 to
ef6ed7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
value[x]) to exactly one variant (e.g.,valueQuantity), flatten the API so users write{ value: 120, unit: "mmHg" }instead of{ valueQuantity: { value: 120, unit: "mmHg" } }category,component) into optionalcreate()params — required slice stubs are auto-merged when missingwrapSliceChoiceandflattenSliceChoiceruntime helperselementsthrough TypeSchema for constrained choice detectionTest plan
bun run typecheck && bun run lint && bun testpassessetSystolicBP({ value: 120, unit: "mmHg" })workscreate()with empty/partial/full category arrays🤖 Generated with Claude Code