So to go into more detail... I followed this example to add types to the component created by SliceMachine.
This is what my component looks like:
import {
PrismicLink,
PrismicText,
SliceComponentProps,
} from '@prismicio/react';
import * as prismicT from '@prismicio/types';
export type SocialMediaServiceSlice = prismicT.Slice<
'footer_social_media_service',
{
'social-media-service': prismicT.RichTextField;
'social-media-link': prismicT.LinkField;
}
>;
const FooterSocialMediaService = ({
slice,
}: SliceComponentProps<SocialMediaServiceSlice>) => (
<li>
{slice.primary['social-media-link'] ? (
<PrismicLink field={slice.primary['social-media-link']}>
{slice.primary['social-media-service'] ? (
<PrismicText field={slice.primary['social-media-service']} />
) : (
<span>A social media service</span>
)}
</PrismicLink>
) : null}
</li>
);
export default FooterSocialMediaService;
But that creates an issue in the slice-simulator.tsx
with the components
prop on the SliceZone
component.
The full error is:
Type '{ footer_social_media_service: ({ slice, }: SliceComponentProps<SocialMediaServiceSlice, unknown>) => JSX.Element; }' is not assignable to type 'SliceZoneComponents<Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice<string, SharedSliceVariation<string, Record<...>, Record<...>>>, unknown>'.
Property 'footer_social_media_service' is incompatible with index signature.
Type '({ slice, }: SliceComponentProps<SocialMediaServiceSlice>) => JSX.Element' is not assignable to type 'SliceComponentType<Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice<string, SharedSliceVariation<string, Record<...>, Record<...>>>, unknown>'.
Type '({ slice, }: SliceComponentProps<SocialMediaServiceSlice>) => JSX.Element' is not assignable to type 'FunctionComponent<SliceComponentProps<Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice<string, SharedSliceVariation<string, Record<...>, Record<...>>>, unknown>>'.
Types of parameters '__0' and 'props' are incompatible.
Type 'PropsWithChildren<SliceComponentProps<Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice<string, SharedSliceVariation<string, Record<...>, Record<...>>>, unknown>>' is not assignable to type 'SliceComponentProps<SocialMediaServiceSlice, unknown>'.
Types of property 'slice' are incompatible.
Type 'Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice<string, SharedSliceVariation<string, Record<string, AnyRegularField>, Record<...>>>' is not assignable to type 'SocialMediaServiceSlice'.
Type 'Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>>' is not assignable to type 'Slice<"footer_social_media_service", { 'social-media-service': [] | [RTNode, ...RTNode[]]; 'social-media-link': FilledLinkToDocumentField<string, string, never> | EmptyLinkField<...> | FilledLinkToWebField | FilledLinkToMediaField; }, Record<...>>'.
Type 'string' is not assignable to type '"footer_social_media_service"'.ts(2322)
index.d.ts(686, 5): The expected type comes from property 'components' which is declared here on type 'IntrinsicAttributes & SliceZoneProps<Slice<string, Record<string, AnyRegularField>, Record<string, AnyRegularField>> | SharedSlice<...>, unknown>'
Apart from the example I followed, I can't find anything else to help...
Is there anyone with any tips?