Skip to content

Type InferSlots<T> ​

InferSlots<T> = { [K in keyof T & string as K extends `render${infer Key}` ? Key : never]: Exclude<T[K], undefined> }

Source: slots.tsx

Infers the dictionary that maps slot names to components from the props of a component with slots (e.g., a component with props of type PropsWithSlots).

Type Parameters ​

T ​

T extends Slots<Record<string, FC>>

Example ​

From props ​

This can be used to infer the slots from the props of a component with slots:

ts
type MyProps = PropsWithSlots<{ SlotA: FC; SlotB: FC }>;
type MySlots = InferSlots<MyProps>; // Result: { SlotA: FC; SlotB: FC }

From a component ​

This can also be used in combination with ComponentProps to infer the slots directly from a component with slots.

ts
function MyComponent(props: PropsWithSlots<{ SlotA: FC; SlotB: FC }>) {
	// ...
}

type MySlots = InferSlots<ComponentProps<typeof MyComponent>>; // Result: { SlotA: FC; SlotB: FC }

Built by Prozilla