Skip to content

How to fix "Property 'type' is missing" error?

TypeScript reports this error when a chart component requires the type prop and does not get it:

Property 'type' is missing in type '{ data: ChartData<"line", (number | Point | null)[], unknown>; }' but required in type 'ChartProps<"line", (number | Point | null)[], unknown>'.

The <Chart> component draws a chart of any type, so it needs the type prop:

<Chart type='line' data={data} />

Typed components, such as <Line>, set the type themselves and have no type prop:

<Line data={data} />

ChartProps are the props of <Chart>, so type is required in them. A component that takes ChartProps<'line'> and renders <Line> passes this requirement on to the code that renders it:

function SalesChart(props: ChartProps<'line'>) {
return <Line {...props} />;
}
<SalesChart data={data} />; // Property 'type' is missing

Take the props of the typed component instead, with ComponentProps of React, or leave type out of ChartProps:

import type { ComponentProps } from 'react';
import { Line, type ChartProps } from 'react-chartjs-2';
function SalesChart(props: ComponentProps<typeof Line>) {
return <Line {...props} />;
}
function OrdersChart(props: Omit<ChartProps<'line'>, 'type'>) {
return <Line {...props} />;
}

In react-chartjs-2 3.0.3 and older, the typed components required type too, so <Line data={data} /> failed with an error that ends with but required in type 'Props'. Version 3.0.4 fixed the types: update react-chartjs-2 and remove the type prop from typed components, which no longer accept it.

See also How to use react-chartjs-2 with TypeScript?.