fix: support untyped or partially typed Slices in <SliceZone>
#154
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.
Types of changes
Description
This PR changes
<SliceZone>
to accept untyped or partially typed Slices. The changes affect both the provided Slices (theslices
prop) and components (thecomponents
prop).It effectively removes any type checking between the
slices
andcomponents
props.It also defaults Slice components'
slice
prop toany
rather thanSliceLike
. This was done to support Prismic's Rest API and GraphQL API with the same set of types.Developers can still provide types to their API responses via
@prismicio/client
's type parameters and Slice components via@prismicio/react
'sSliceComponentProps
. This PR does not include breaking changes.While these changes may seem like a step backwards, it broadens the library's support to include projects with insufficient type data. Today, projects with insufficient types is common. This can happen when Slice components are properly typed, but the API data is not. This is even the case in Prismic-provided integrations like Slice Simulator.
Rather than force developers to hand-type their projects, the library has been updated to gracefully support untyped or partially typed data and components.
For more details on what prompted this change, see prismicio/prismic-types#34.
Component Type Examples
<SliceZone>
will accept any of these typed components.Fully typing a Slice component for Prismic's Rest API:
Fully typing a Slice component for Prismic's GraphQL API using a generated type (e.g. from GraphQL Code Generator):
Partially typing a Slice component (restricted to Prismic's Rest API):
Partially typing a Slice component (restricted to Prismic's GraphQL API):
Partially typing a Slice component (any API):
Checklist:
🦢