Skip to content

Commit 681e0e1

Browse files
committed
fix(types): fix types error
1 parent 771acc2 commit 681e0e1

File tree

48 files changed

+131
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+131
-175
lines changed

__tests__/plots/line.spec.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React, { createRef } from 'react'
22
import ReactDOM from 'react-dom'
33
import LineChart from '../../src/plots/line'
44
import StateManagerProvider from '../../src/components/state-manager'
5-
import { StateManager } from '@antv/g2plot'
5+
import { StateManager, LineConfig } from '@antv/g2plot'
6+
import BasePlot from '@antv/g2plot/lib/base/plot'
67

78
describe('LineChart', () => {
89
test('render without crashed', () => {
@@ -11,8 +12,8 @@ describe('LineChart', () => {
1112
})
1213

1314
test('object ref should be assigned', () => {
14-
const ref = createRef<any>()
15-
const chartRef = createRef()
15+
const ref = createRef<HTMLDivElement | null>()
16+
const chartRef = createRef<BasePlot<LineConfig> | null>()
1617
const div = document.createElement('div')
1718
ReactDOM.render(<LineChart data={[]} ref={ref} chartRef={chartRef} />, div)
1819
expect(ref.current).toBeDefined()
@@ -25,7 +26,7 @@ describe('LineChart', () => {
2526
expect(instance).toBeTruthy()
2627
}
2728
const div = document.createElement('div')
28-
ReactDOM.render(<LineChart data={[]} ref={getChart} />, div)
29+
ReactDOM.render(<LineChart data={[]} chartRef={getChart} />, div)
2930

3031
// expect(chart).toBeDefined()
3132
})

src/components/base/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const syncRef = <C extends PlotConfig>(
7171
export interface BaseChartProps<C extends PlotConfig>
7272
extends Pick<HTMLAttributes<HTMLDivElement>, PickedAttrs> {
7373
chart: Plot<C>
74-
chartRef: Ref<BasePlot<C, LayerCtor<C>> | null>
74+
chartRef?: Ref<BasePlot<C, LayerCtor<C>> | null>
7575
stateManager?: StateManagerCfg
7676
}
7777

@@ -94,7 +94,6 @@ const BaseChart = <C extends PlotConfig>(
9494
const isFirstRenderRef = useRef<boolean>(true)
9595

9696
useImperativeHandle(ref, () => containerRef.current)
97-
useImperativeHandle(chart, () => chartRef.current)
9897

9998
useEffect(() => {
10099
const { current: container } = containerRef
@@ -148,5 +147,5 @@ const BaseChart = <C extends PlotConfig>(
148147
}
149148

150149
export default forwardRef(BaseChart) as <C extends PlotConfig>(
151-
p: BaseChartProps<C> & RefAttributes<BasePlot<C, LayerCtor<C>> | null>
150+
p: BaseChartProps<C> & RefAttributes<HTMLDivElement | null>
152151
) => ReactElement

src/plots/area/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { forwardRef } from 'react'
2-
import { Area, AreaConfig, Base as BasePlot } from '@antv/g2plot'
2+
import { Area, AreaConfig } from '@antv/g2plot'
33
import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type AreaChartProps = Omit<BaseChartProps<AreaConfig>, 'chart'> &
66
AreaConfig
77

8-
const AreaChart = forwardRef<BasePlot<AreaConfig>, AreaChartProps>(
8+
const AreaChart = forwardRef<HTMLDivElement | null, AreaChartProps>(
99
(props, ref) => {
1010
return <BaseChart chart={Area} ref={ref} {...props} />
1111
}

src/plots/bar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { forwardRef } from 'react'
2-
import { Bar, BarConfig, Base as BasePlot } from '@antv/g2plot'
2+
import { Bar, BarConfig } from '@antv/g2plot'
33
import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type BarChartProps = Omit<BaseChartProps<BarConfig>, 'chart'> & BarConfig
66

7-
const BarChart = forwardRef<BasePlot<BarConfig>, BarChartProps>(
7+
const BarChart = forwardRef<HTMLDivElement | null, BarChartProps>(
88
(props, ref) => {
99
return <BaseChart chart={Bar} ref={ref} {...props} />
1010
}

src/plots/bubble/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { forwardRef } from 'react'
2-
import { Bubble, BubbleConfig, Base as BasePlot } from '@antv/g2plot'
2+
import { Bubble, BubbleConfig } from '@antv/g2plot'
33
import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type BubbleChartProps = Omit<BaseChartProps<BubbleConfig>, 'chart'> &
66
BubbleConfig
77

8-
const BubbleChart = forwardRef<BasePlot<BubbleConfig>, BubbleChartProps>(
8+
const BubbleChart = forwardRef<HTMLDivElement | null, BubbleChartProps>(
99
(props, ref) => {
1010
return <BaseChart chart={Bubble} ref={ref} {...props} />
1111
}

src/plots/bullet/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { forwardRef } from 'react'
2-
import { Bullet, BulletConfig, Base as BasePlot } from '@antv/g2plot'
2+
import { Bullet, BulletConfig } from '@antv/g2plot'
33
import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type BulletChartProps = Omit<BaseChartProps<BulletConfig>, 'chart'> &
66
BulletConfig
77

8-
const BulletChart = forwardRef<BasePlot<BulletConfig>, BulletChartProps>(
8+
const BulletChart = forwardRef<HTMLDivElement | null, BulletChartProps>(
99
(props, ref) => {
1010
return <BaseChart chart={Bullet} ref={ref} {...props} />
1111
}

src/plots/calendar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { forwardRef } from 'react'
2-
import { Calendar, CalendarConfig, Base as BasePlot } from '@antv/g2plot'
2+
import { Calendar, CalendarConfig } from '@antv/g2plot'
33
import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type CalendarChartProps = Omit<BaseChartProps<CalendarConfig>, 'chart'> &
66
CalendarConfig
77

8-
const CalendarChart = forwardRef<BasePlot<CalendarConfig>, CalendarChartProps>(
8+
const CalendarChart = forwardRef<HTMLDivElement | null, CalendarChartProps>(
99
(props, ref) => {
1010
return <BaseChart chart={Calendar} ref={ref} {...props} />
1111
}

src/plots/column-line/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { forwardRef } from 'react'
2-
import { ColumnLine, ColumnLineConfig, Base as BasePlot } from '@antv/g2plot'
2+
import { ColumnLine, ColumnLineConfig } from '@antv/g2plot'
33
import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type ColumnLineChartProps = Omit<
@@ -8,11 +8,10 @@ export type ColumnLineChartProps = Omit<
88
> &
99
ColumnLineConfig
1010

11-
const ColumnLineChart = forwardRef<
12-
BasePlot<ColumnLineConfig>,
13-
ColumnLineChartProps
14-
>((props, ref) => {
15-
return <BaseChart chart={ColumnLine} ref={ref} {...props} />
16-
})
11+
const ColumnLineChart = forwardRef<HTMLDivElement | null, ColumnLineChartProps>(
12+
(props, ref) => {
13+
return <BaseChart chart={ColumnLine} ref={ref} {...props} />
14+
}
15+
)
1716

1817
export default ColumnLineChart

src/plots/column/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { forwardRef } from 'react'
2-
import { Column, ColumnConfig, Base as BasePlot } from '@antv/g2plot'
2+
import { Column, ColumnConfig } from '@antv/g2plot'
33
import BaseChart, { BaseChartProps } from '../../components/base'
44

55
export type ColumnChartProps = Omit<BaseChartProps<ColumnConfig>, 'chart'> &
66
ColumnConfig
77

8-
const ColumnChart = forwardRef<BasePlot<ColumnConfig>, ColumnChartProps>(
8+
const ColumnChart = forwardRef<HTMLDivElement | null, ColumnChartProps>(
99
(props, ref) => {
1010
return <BaseChart chart={Column} ref={ref} {...props} />
1111
}

src/plots/density-heatmap/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import React, { forwardRef } from 'react'
2-
import {
3-
DensityHeatmap,
4-
DensityHeatmapConfig,
5-
Base as BasePlot,
6-
} from '@antv/g2plot'
2+
import { DensityHeatmap, DensityHeatmapConfig } from '@antv/g2plot'
73
import BaseChart, { BaseChartProps } from '../../components/base'
84

95
export type DensityHeatmapChartProps = Omit<
@@ -13,7 +9,7 @@ export type DensityHeatmapChartProps = Omit<
139
DensityHeatmapConfig
1410

1511
const DensityHeatmapChart = forwardRef<
16-
BasePlot<DensityHeatmapConfig>,
12+
HTMLDivElement | null,
1713
DensityHeatmapChartProps
1814
>((props, ref) => {
1915
return (

0 commit comments

Comments
 (0)