Skip to content

Commit 4600d8f

Browse files
committed
refactor: simplify type definitions and remove redundant compose type assertions
1 parent 484a484 commit 4600d8f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/charts.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function assignForwardedRef<T>(ref: React.ForwardedRef<T>, value: T | null) {
3737
else ref.current = value;
3838
}
3939

40-
interface ChartBaseProps<T extends readonly ChartComponentType<any>[]> {
40+
interface ChartBaseProps<T extends readonly ChartComponentType[]> {
4141
className?: string;
4242
style?: React.CSSProperties;
4343
containerProps?: React.HTMLAttributes<HTMLDivElement>;
@@ -46,16 +46,19 @@ interface ChartBaseProps<T extends readonly ChartComponentType<any>[]> {
4646
children?: React.ReactNode;
4747
}
4848

49-
type InferChartComponentOption<
50-
T extends readonly ChartComponentType<any>[],
51-
U = T[number]
52-
> = U extends ChartComponentType<infer P> ? P : never;
49+
type ResolveComposeOption<T extends ComponentOption | ChartComponentType> = T extends ComponentOption
50+
? T
51+
: T extends ChartComponentType<infer P>
52+
? P
53+
: never;
5354

54-
interface ChartComponentType<T extends ComponentOption> {
55-
<U extends readonly ChartComponentType<any>[] = []>(
55+
interface ChartComponentType<in T extends ComponentOption = any> {
56+
<U extends readonly ChartComponentType[] = []>(
5657
props: ChartBaseProps<U> &
5758
echarts.EChartsCoreOption &
58-
Simplify<ComposeOption<T | InferChartComponentOption<U>>> & { ref?: React.Ref<echarts.ECharts> }
59+
Simplify<ComposeOption<ResolveComposeOption<T | U[number]>>> & {
60+
ref?: React.Ref<echarts.ECharts>;
61+
}
5962
): React.JSX.Element;
6063

6164
ext: EChartExt;

stories/scatter.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ export const CalendarCharts: Story = {
10371037

10381038
return (
10391039
<ScatterChart
1040-
compose={[EffectScatterChart, GraphChart, HeatmapChart] as const}
1040+
compose={[EffectScatterChart, GraphChart, HeatmapChart]}
10411041
style={{ width: 800, height: 700 }}
10421042
series={[
10431043
{

0 commit comments

Comments
 (0)