Closed Laruxo closed 1 year ago
This issue has been labeled as a feature request since it was created using the 🙋♀️ Feature Request Template.
Hi there, thank you so much for your request!
Following our Maintenance Process, we will review your request and get back to you soon. If we decide to implement it, will proceed to implement the feature during the last week of the month. In the meantime, feel free to provide any details to help us better understand your request, such as:
If you think you can implement the proposed change yourself, you're more than welcome to open a pull request implementing the new feature. Check out our quick start guide for a simple contribution process. Please note that submitting a pull request does not guarantee the feature will be merged.
- The Prismic Open-Source Team
Hi @Laruxo, I'm sorry for the late reply.
State extends "empty" ? [] : [RTNode, ...RTNode[]]
was preferred over RTNode[]
because it more explicitly defines what happens when a field is empty or filled.
The State
type parameter allows the types to be smart enough to tell you when you are passing a field value into something that expects a filled value. @prismicio/client
's isFilled
helpers (e.g. isFilled.image(imageField)
), lets you narrow the type to a filled or empty value. That narrowing could help write stronger code that is type checked. If you don't use the isFilled
helpers, should still be able to conditionally access properties by performing other runtime checks.
We recommend that you use the field-level types from @prismicio/client
rather than the lower-level types like RTNode
and Slice[]
. For example, you can use RichTextField
and SliceZone
instead.
I'll leave this topic open for now in case you or anyone else would like to share other viewpoints. What I explained above details our original design, but that doesn't mean we can't change it. 🙂
Closing as stale, happy to reopen if anyone wants to continue the discussion~
Thanks for contributing!
Is your feature request related to a problem? Please describe.
I am a bit frustrated with the use of this pattern:
In my code, I have custom types holding data like
nodes: RTNode[]
orslices: Slice[]
. However, these types are not compatible with[] | [RTNode, ...RTNode[]]
.I would love to hear more context about this pattern and why did you decide to use it instead of
never[] | RTNode[]
.Describe the solution you'd like
Ideally, Typescript would understand that
[] | [RTNode, ...RTNode[]]
is equivalent toRTNode[]
(both ways). Until then I would prefer simpler types without thisState
(e.g.never[] | RTNode[]
)