Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@nivo/calendar type CalendarDatum is missing 'data' property #2603

Open
mariodeckers opened this issue Jun 3, 2024 · 0 comments
Open

@nivo/calendar type CalendarDatum is missing 'data' property #2603

mariodeckers opened this issue Jun 3, 2024 · 0 comments

Comments

@mariodeckers
Copy link

The documents https://nivo.rocks/time-range/ explain how one can add arbitrary data to the data object:

dataobject[]required
Chart data.
Chart data, which must conform to this structure:

Array<{
day: string, // format must be YYYY-MM-DD
value: number
}>
You can also add arbitrary data to this structure to be used in tooltips or event handlers.

However, when trying to do so, TypeScript complains that property 'data' does not exist...

E.g.

export default function NivoTimeRange({ chartdata }: { chartdata: CalendarDatum[] }) {
  return (
    <ResponsiveTimeRange
        data={chartdata}
        from="2024-01-01"
        to="2024-08-31"
        onClick={(datum: TimeRangeDayData) => console.log(datum.data)}
        tooltip={(e: CalendarTooltipProps) => <div>{e.data}</div>}
    />
  )
}

TypeScript error:
Property 'data' does not exist on type 'TimeRangeDayData'.
Property 'data' does not exist on type 'CalendarDatum & { coordinates: { x: number; y: number; }; date: Date; firstWeek: number; month: number; year: number; color: string; width: number; height: number; }'.

Indeed types are:

export type CalendarDatum = {
    day: string;
    value: number;
};

export type CalendarTooltipProps = {
    value: string;
    day: string;
    color: string;
};

export type TimeRangeDayData = (Omit<CalendarDatum, 'value'> | CalendarDatum) & {
    coordinates: {
        x: number;
        y: number;
    };
    date: Date;
    firstWeek: number;
    month: number;
    year: number;
    color: string;
    width: number;
    height: number;
};

Similarly to other chart types, I would expect that the types get [key: string]: any added to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant