Description
At the moment, the exposed types aren't very user-friendly.
From my point of view, there's two problems we need to solve:
- Expose simpler types, and
- Expose flatter types
Expose Simpler Types
For example, if you want to define a variable that satisfies the x-axis of a bar chart, you can't do:
const xAxis = { } satisfies XAxis;
Instead, you can do:
const xAxis = { } satisfies MakeOptional<AxisConfig<ScaleName, any, ChartsXAxisProps>, 'id'>[]
Which is the type that is defined in UseChartCartesianAxisParameters
. The problem is that MakeOptional
is internal, so external users can't access it properly.
Another cleaner but less beginner-friendly option is:
const xAxis = {} satisfies UseChartCartesianAxisParameters['xAxis'][number];
But this is, in my opinion, far from ideal.
Expose flatter types
Currently, if you Cmd/Ctrl+Click (at least on my IDE) in BarChart
's xAxis
prop, you get redirected to this interface definition:
export interface UseChartCartesianAxisParameters {
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used.
* An array of [[AxisConfig]] objects.
*/
xAxis?: readonly MakeOptional<AxisConfig<ScaleName, any, ChartsXAxisProps>, 'id'>[];
// ...
}
This type isn't very beginner friendly and requires understanding of four separate types: MakeOptional
, AxisConfig
, ScaleName
and ChartsXAxisProps
.
In my opinion, we should try to make the exposed types flatter and derive our internal representation from them, instead of the other way around.
Another option would be to see if there's some TypeScript utility that allows us to flatten types when building. That way we could keep our current state, but the external facing types would be easier to read. This would likely require less work with refactoring types, but I'm not sure if such a tool exists.
@alexfauquette @JCQuintas curious to hear your thoughts.