I have a component with these props:
type Props = {
items: {
text: string;
status?: "processing" | "error" | "info-required";
}[];
};
const Component: React.FC<Props> = ({ items }) =>
When I use the component and set the props inline it works fine:
<Component
items={[
{ text: "a" },
{ text: "b" },
{ text: "c", status: "processing" }
]}
/>
However when I put the props in an object it errors:
const items = [
{ text: "a" },
{ text: "b" },
{ text: "c", status: "processing" }
]
<Component items={items} />
Types of property 'status' are incompatible. Type 'string' is not assignable to type '"error" | "processing" | "info-required"'.
The expected type comes from property 'items' which is declared here on type 'IntrinsicAttributes & Props & { children?: ReactNode; }'


statusin theitemsvariable isstring. If you copy the type of theitemsproperty inPropsover, it'll work. E.g. tryconst items: typeof Props['items'] = ...typeofthought, becauseProps['items']already reference{ text : string, status ?: '...' }