Closed Klynger closed 2 years ago
This issue has been labeled as a bug since it was created using the 🚨 Bug Report Template.
Hi there, thank you so much for the report!
Following our Maintenance Process, we will review your bug report and get back to you next Wednesday. To ensure a smooth review of your issue and avoid unnecessary delays, please make sure your issue includes the following:
package.json
file.If you have identified the cause of the bug described in your report and know how to fix it, you're more than welcome to open a pull request addressing it. Check out our quick start guide for a simple contribution process.
If you think your issue is a question (not a bug) and would like quicker support, please close this issue and forward it to an appropriate section on our community forum: https://community.prismic.io
- The Prismic Open-Source Team
Hi @Klynger,
Thanks for reporting this issue. This is actually intentional; SharedSliceVariation
is intended to be used along with SharedSlice
. SharedSlice
contains slice_type
and accepts a union of SharedSliceVariation
types.
You can see the SharedSlice
type definition here: https://github.com/prismicio/prismic-types/blob/f7c39e38ead6aae8527dd07259359f6fab610c9f/src/fields.ts#L820-L826
You would use it like this:
import * as prismicT from '@prismicio/types'
type ImageSlice = prismicT.SharedSlice<
"image",
ImageSliceDefault | ImageSliceWithCaption
>
type ImageSliceDefault = prismicT.SharedSliceVariation<
"default",
{
image: prismicT.ImageField;
},
never
>
type ImageSliceWithCaption = prismicT.SharedSliceVariation<
"withCaption",
{
image: prismicT.ImageField;
caption: prismicT.RichTextField;
},
never
>
We just released a new tool call prismic-ts-codegen
that can generate all of these types for you automatically. I recommend using that tool over writing the types by hand.
# Install the codegen tool
npm install --save-dev prismic-ts-codegen @prismicio/types
# Create a prismicCodegen.config.ts configuration file
npx prismic-ts-codegen init
# Generate types
npx prismic-ts-codegen
You can learn more about the tool here: https://prismic.io/docs/technical-reference/prismic-ts-codegen
That's amazing! Thank you, @angeloashmore
Versions
Reproduction
Steps to reproduce
Just use the type
What is expected?
The type to have a definition for
slice_type
.What is actually happening?
The type doesn't have a definition for
slice_type