Skip to content

Commit 63e1253

Browse files
committed
fix: Solve the options type conflict caused by multiple type files. Add test cases for the corresponding options type
1 parent e150dc1 commit 63e1253

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

__tests__/charts/simple-spec.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import ReactECharts from '../../src/';
33
import type { EChartsOption } from '../../src/';
4+
import type { EChartsOption as DefaultEChartsOption } from 'echarts/types/dist/shared';
5+
import type { EChartsOption as SharedComponentEChartsOption } from 'echarts';
46
import { render, destroy, createDiv, removeDom } from '../utils';
57

68
const options: EChartsOption = {
@@ -36,6 +38,68 @@ describe('chart', () => {
3638
removeDom(div);
3739
});
3840

41+
it('DefaultEChartsOption', () => {
42+
let instance;
43+
const div = createDiv();
44+
const defaultOptions: DefaultEChartsOption = {
45+
xAxis: {
46+
type: 'category',
47+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
48+
},
49+
yAxis: {
50+
type: 'value',
51+
},
52+
series: [
53+
{
54+
data: [820, 932, 901, 934, 1290, 1330, 1320],
55+
type: 'line',
56+
smooth: true,
57+
},
58+
],
59+
};
60+
const Comp = <ReactECharts ref={(e) => (instance = e)} option={defaultOptions} />;
61+
render(Comp, div);
62+
63+
expect(instance).toBeDefined();
64+
expect(instance.getEchartsInstance()).toBeDefined();
65+
66+
destroy(div);
67+
expect(div.querySelector('*')).toBe(null);
68+
69+
removeDom(div);
70+
});
71+
72+
it('SharedComponentEChartsOption', () => {
73+
let instance;
74+
const div = createDiv();
75+
const sharedOptions: SharedComponentEChartsOption = {
76+
xAxis: {
77+
type: 'category',
78+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
79+
},
80+
yAxis: {
81+
type: 'value',
82+
},
83+
series: [
84+
{
85+
data: [820, 932, 901, 934, 1290, 1330, 1320],
86+
type: 'line',
87+
smooth: true,
88+
},
89+
],
90+
};
91+
const Comp = <ReactECharts ref={(e) => (instance = e)} option={sharedOptions} />;
92+
render(Comp, div);
93+
94+
expect(instance).toBeDefined();
95+
expect(instance.getEchartsInstance()).toBeDefined();
96+
97+
destroy(div);
98+
expect(div.querySelector('*')).toBe(null);
99+
100+
removeDom(div);
101+
});
102+
39103
describe('container size', () => {
40104
it('default', () => {
41105
let instance;

src/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { CSSProperties } from 'react';
2-
import type { EChartsOption, EChartsType } from 'echarts';
2+
import type { EChartsOption as DefaultEChartsOption, EChartsType } from 'echarts';
3+
import type { EChartsOption as SharedComponentEChartsOption } from 'echarts/types/dist/shared';
34

4-
export type { EChartsOption };
5+
/**
6+
* Solve the type conflict caused by multiple type files
7+
*/
8+
export type EChartsOption = DefaultEChartsOption | SharedComponentEChartsOption;
59

610
export type EChartsInstance = EChartsType;
711

0 commit comments

Comments
 (0)