Skip to content

[charts] Provide context-aware types based on props #14340

Open
@JCQuintas

Description

@JCQuintas

A current frustration with types right now is that we can't provide context aware types for the users due to how our types are declared.

This change could provide valuable IDE information to our final users in how the components can be used.

Example

import * as React from 'react';

type Prop1 = {
  height: number;
  width: number;
  data: number[];
  responsive?: never;
};

type Prop2 = {
  responsive: true;
  data: string[];
};

type Props = Prop1 | Prop2;

const Component = (props: Props) => {
  return null;
};

export default function Page() {
  return (
    <>
      <Component responsive data={['aaa']} />
      <Component height={1} width={2} data={[2]} />
      {/* Unexpected prop value */}
      <Component responsive={false} />
      {/* Data should be string when used with responsive */}
      <Component responsive data={[1]} />
    </>
  );
}

Possible implementations

  • All charts:
    • dataset vs no dataset
      • The dataset mode could require that the dataKey is set in the series
      • data mode would forbid dataKey and require data

Search keywords:

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeIntroduces changes that are not backward compatible.scope: chartsChanges or issues related to the charts productv8.x

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions