-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: add State
generic to field types
#13
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 59 59
=========================================
Hits 59 59
Continue to review full report at Codecov.
|
IsEmpty
generic to emptyable field types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, that's quite a weird way of doing a "union if" but seems like the only way ^^'
Maybe you can add a short TSDoc for the isEmpty
type params to explain it (others can be postponed for now)
If boolean is still too obscure have you considered using a string type? Something like this (not as nice maybe but I actually quite like it, and gives the "filled" state as a bonus
// Union let a hint of what's expected(?)
export type ImageFieldImage<State extends "empty" | "filled" = "empty" | "filled"> =
State extends "empty"
? EmptyImageFieldImage
: FilledImageFieldImage;
Schrodinger's types 🤔
Great idea! import * as prismicT from '@prismicio/types'
type MyField = prismicT.SelectField<"Option 1" | "Option 2", "empty">
// MyField === null I'll add TSDocs for the new generic before considering this ready to merge. |
IsEmpty
generic to emptyable field typesState
generic to emptyable field types
State
generic to emptyable field typesState
generic to field types
Types of changes
Description
This PR adds a
State
generic to field types that can be empty. For example, a Select field can be empty which returnsnull
rather than astring
.In the following example,
State
is the second generic.To explicitly set the field as "filled":
By default, the state is ambiguous (i.e. "empty" | "filled"):
Related
@prismicio/mock
PR: prismicio/prismic-mock#4Checklist:
🦮