I am again fixing full blocker issues following a new update/fix of Slicemachine:
Type '{ blog_post_banner: ComponentType<BlogPostBannerProps>; content_block: ComponentType<TextContentProps>; ... 19 more ...; text_content: ComponentType<...>; }' is not assignable to type 'Record<string, SliceComponentType<any, unknown>>'.ts(2322)
SliceZone.d.ts(150, 5): The expected type comes from property 'components' which is declared here on type 'IntrinsicAttributes & SliceZoneProps<unknown>'
(property) components?: Record<string, SliceComponentType<any, unknown>> | undefined
A record mapping Slice types to React components.
I do not understand why every update is breaking everything
I have isolated that branch, everything is fine if I work on another branch if I am not doing that upgrade of slicemachine, so it definitely has to do with this upgrade?
The TypeScript issue is definitely not intentional.
It looks like one or more of your Slice components do not adhere to SliceComponentType. The SliceComponentType type enforces that a Slice component accepts the following props:
slice: The Slice object being rendered.
index: The index of the Slice within the Slice Zone.
slices: The list of all Slice objects in the Slice Zone.
context: Arbitrary data passed to the <SliceZone>'s context prop.
// src/slices/Text/index.tsx
import type { Content } from '@prismicio/client'
import type { SliceComponentProps } from '@prismicio/react'
export type TextProps = SliceComponentProps<Content.TextSlice>
export default function Text({ slice }: TextProps) {
// `slice` is typed as TextSlice.
}
Note the use of SliceComponentProps and Content.
If this does not resolve the TypeScript error, we will need more information to understand the issue. You can get the full TypeScript error by running the following command in your project:
npx tsc --noEmit
If you receive more errors than the one you shared above, please share only the SliceComponentType error so we can pinpoint the issue.
Weirdly, I do not have that issue anymore when trying on another brand new branch... (Have tried that previously on a new branch, and the issue was coming out again).
The thing is, that the whole application is in TypeScript, but we kept the slices in Javascript so far (index.js). So even weirder that this kind of bug popped out. Maybe it forced the rewriting of the slices as .ts with the same content, I dont know...
The only warning I got re-installing it now is:
WARN Issues with peer dependencies found
.
└─┬ slice-machine-ui 1.0.3
└─┬ @prismicio/editor-fields 0.3.0
└── ✕ unmet peer @prismicio/editor-ui@0.3.0: found 0.3.1 in slice-machine-ui
I will investigate further in this end of week, I will reopen that ticket if the issue comes back in any form.
That peer dependency warning should be safe to ignore. If it is blocking your project from installing dependencies, you can install them with the --legacy-peer-deps flag.
npm install --legacy-peer-deps
I notified the Slice Machine development team of the issue. I don't have an estimate on when the fix will be published, but they are aware of it.
Actually the error is back following me creating a new slice type:
Type error: Type '{ all_blog_posts: ComponentType<{}>; blog_post_banner: ComponentType<BlogPostBannerProps>; content_block: ComponentType<TextContentProps>; ... 19 more ...; text_content: ComponentType<...>; }' is not assignable to type 'Record<string, SliceComponentType<any, unknown>>'.
Property 'all_blog_posts' is incompatible with index signature.
Type 'ComponentType<{}>' is not assignable to type 'SliceComponentType<any, unknown>'.
Type 'ComponentClass<{}, any>' is not assignable to type 'SliceComponentType<any, unknown>'.
Type 'ComponentClass<{}, any>' is not assignable to type 'ComponentClass<SliceComponentProps<any, unknown>, any>'.
Construct signature return types 'Component<{}, any, any>' and 'Component<SliceComponentProps<any, unknown>, any, any>' are incompatible.
The types of 'props' are incompatible between these types.
Type 'Readonly<{}>' is missing the following properties from type 'Readonly<SliceComponentProps<any, unknown>>': slice, index, slices, context
Could it be because my old slices are still a .js file (index.js)? But my new one, for instance the one that triggered the but, is in TS (index.tsx):
This slice has been deleted actually (all_blog_posts). Redeleted it from slicemachine.
Now its blog_post_banner the issue:
./pages/[uid].tsx:57:9
Type error: Type '{ blog_post_banner: ComponentType<BlogPostBannerProps>; content_block: ComponentType<TextContentProps>; ... 19 more ...; text_content: ComponentType<...>; }' is not assignable to type 'Record<string, SliceComponentType<any, unknown>>'.
Property 'data_guide_cta' is incompatible with index signature.
Type 'ComponentType<{}>' is not assignable to type 'SliceComponentType<any, unknown>'.
Type 'ComponentClass<{}, any>' is not assignable to type 'SliceComponentType<any, unknown>'.
Type 'ComponentClass<{}, any>' is not assignable to type 'ComponentClass<SliceComponentProps<any, unknown>, any>'.
Construct signature return types 'Component<{}, any, any>' and 'Component<SliceComponentProps<any, unknown>, any, any>' are incompatible.
The types of 'props' are incompatible between these types.
Type 'Readonly<{}>' is missing the following properties from type 'Readonly<SliceComponentProps<any, unknown>>': slice, index, slices, context
55 | <SliceZone
56 | slices={page.data.slices}
> 57 | components={components}
| ^
58 | context={{ similarPages }}
59 | />
60 | <Statistics />
I think it's just showing the first slice by alphabetical order basically.
Here's for instance the BlogPostBanner slice as index.js:
I dont know if that jumped or else during the update, or if it was never required before, but is there a way to automatically regenerate it for all slices? that @param@typedef part?
That is not totally related but still - Making sure there's not a bug in the patch:
I have deleted a legacy slice named "quote" from slicemachine. The index.js and schema json of this slice has been correctly deleted automatically. Although, unfortunately, it seems that the master slices>index.js importing all the slices has not been automatically updated, because I am still seeing the importation of this deleted slice:
./slices/index.js:18:0
Module not found: Can't resolve './Quote'
16 | import NewsletterBasic from './NewsletterBasic'
17 | import PillarBanner from './PillarBanner'
> 18 | import Quote from './Quote'
How come? Is it not automatically updated anymore?