From a4d5a2d2e5f10a90fd5942f19b94030501772ab5 Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Thu, 1 Jul 2021 16:24:18 -1000 Subject: [PATCH] fix: more specific SliceZone types --- src/SliceZone.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SliceZone.tsx b/src/SliceZone.tsx index 426203f..faeafc7 100644 --- a/src/SliceZone.tsx +++ b/src/SliceZone.tsx @@ -59,7 +59,10 @@ export type SliceZoneProps = { /** A record mapping Slice types to React components. */ components: Partial< - Record> + Record< + TSlice["slice_type"], + React.ComponentType> + > >; /** The React component rendered if a component mapping from the `components` prop cannot be found. */ @@ -107,9 +110,10 @@ export const SliceZone = ({ }: SliceZoneProps): JSX.Element => { const renderedSlices = React.useMemo(() => { return slices.map((slice, index) => { - const Comp: React.ComponentType = - components[slice.slice_type as keyof typeof components] || - defaultComponent; + const Comp = (components[slice.slice_type as keyof typeof components] || + defaultComponent) as React.ComponentType< + SliceComponentProps + >; const key = JSON.stringify(slice); return (