Skip to content

Commit 0e7530d

Browse files
authored
chore: upgrade typescript to v4 (#3488)
1 parent 8ab57ec commit 0e7530d

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

.eslintrc

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
"no-self-assign": 0,
1818
"no-unused-vars": 0, // @typescript-eslint/no-unused-vars
1919
"no-inner-declarations": 0,
20+
"no-undef": 0,
2021
"prettier/prettier": 2,
22+
"import/order": 2,
23+
"import/no-default-export": 2,
2124
"@typescript-eslint/no-unused-vars": 1,
2225
"@typescript-eslint/no-non-null-assertion": 0,
2326
"@typescript-eslint/no-explicit-any": 0,
@@ -30,9 +33,7 @@
3033
"@typescript-eslint/explicit-function-return-type": 0,
3134
"@typescript-eslint/type-annotation-spacing": 0,
3235
"@typescript-eslint/no-empty-function": 1,
33-
"no-undef": 0,
3436
"@typescript-eslint/no-var-requires": 0,
35-
"import/order": 2,
36-
"import/no-default-export": 2
37+
"@typescript-eslint/ban-ts-comment": 0
3738
}
3839
}

__tests__/unit/core/index-spec.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('core', () => {
211211

212212
it('getChartSize', () => {
213213
createDiv('', document.body, 'changeSize');
214-
document.getElementById('changeSize').style.width = '0px';
214+
document.getElementById('changeSize')!.style.width = '0px';
215215
const line = new Line('changeSize', {
216216
data: partySupport.filter((o) => o.type === 'FF'),
217217
xField: 'date',
@@ -259,8 +259,8 @@ describe('core', () => {
259259

260260
line.render();
261261

262-
expect(line.chart.getOptions().axes['date'].label.autoRotate).toBe(false);
263-
expect(line.chart.getOptions().axes['date'].label.autoHide).toEqual({
262+
expect(line.chart.getOptions().axes?.['date'].label.autoRotate).toBe(false);
263+
expect(line.chart.getOptions().axes?.['date'].label.autoHide).toEqual({
264264
type: 'equidistance',
265265
cfg: {
266266
minGap: 6,
@@ -280,8 +280,8 @@ describe('core', () => {
280280
},
281281
});
282282
line.render();
283-
expect(line.chart.getOptions().axes['date'].label.autoRotate).toBe(false);
284-
expect(line.chart.getOptions().axes['date'].label.autoHide).toEqual({
283+
expect(line.chart.getOptions().axes?.['date'].label.autoRotate).toBe(false);
284+
expect(line.chart.getOptions().axes?.['date'].label.autoHide).toEqual({
285285
type: 'equidistance',
286286
cfg: {
287287
minGap: 12,
@@ -296,14 +296,14 @@ describe('core', () => {
296296
},
297297
});
298298
line.render();
299-
expect(line.chart.getOptions().axes['date'].label.autoRotate).toBe(false);
300-
expect(line.chart.getOptions().axes['date'].label.autoHide).toBe(false);
299+
expect(line.chart.getOptions().axes?.['date'].label.autoRotate).toBe(false);
300+
expect(line.chart.getOptions().axes?.['date'].label.autoHide).toBe(false);
301301

302302
line.destroy();
303303
});
304304

305305
it('default-options', () => {
306-
type CustomPlotOptions = {};
306+
type CustomPlotOptions = Record<string, any>;
307307
class CustomPlot extends Plot<CustomPlotOptions> {
308308
type: 'custom';
309309
getSchemaAdaptor() {
@@ -338,7 +338,7 @@ describe('core', () => {
338338

339339
const annotations = line.chart.getController('annotation').getComponents();
340340
expect(annotations.length).toBe(2);
341-
expect(annotations.find((co) => co.extra.id === 'ID').component.get('type')).toBe('image');
341+
expect(annotations.find((co) => co.extra.id === 'ID')?.component.get('type')).toBe('image');
342342

343343
line.addAnnotations([{ type: 'image', start: ['min', 'median'], end: ['max', 'median'], src: 'xx' }]);
344344
expect(line.chart.getController('annotation').getComponents().length).toBe(3);

__tests__/unit/plots/multi-view/multi-plots-spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ describe('multi-plots in multi-view', () => {
4444
it('innormal, 带不合法的 plot type', () => {
4545
plot.update({
4646
// @ts-ignore `pass illegal type`
47-
plots: [
48-
...plot.options.plots,
47+
plots: (plot.options.plots || []).concat([
4948
{
50-
type: 'xxx',
49+
type: 'xxx' as any,
5150
options: {
5251
data: [
5352
{ x: 'x', y: 1 },
@@ -57,7 +56,7 @@ describe('multi-plots in multi-view', () => {
5756
yField: 'y',
5857
},
5958
},
60-
],
59+
]),
6160
});
6261

6362
expect(plot.chart.views.length).toBe(3);
@@ -129,7 +128,7 @@ describe('multi-plots in multi-view', () => {
129128
},
130129
],
131130
});
132-
const geometries = [];
131+
const geometries: any[] = [];
133132
plot.chart.views.forEach((view) => geometries.push(...view.geometries));
134133
expect(geometries.length).toBe(2);
135134
});

__tests__/unit/plots/scatter/regression-line-spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ describe('scatter', () => {
114114
const { width } = scatter.chart;
115115
const pathGroup = scatter.chart
116116
.getComponents()
117-
.find((item) => item.type === 'annotation')
117+
.find((item) => item.type === 'annotation')!
118118
.component.cfg.group.cfg.children[0].getChildren();
119-
const { path } = pathGroup?.[0]?.cfg?.attrs;
119+
const { path = [] } = pathGroup?.[0]?.cfg?.attrs || {};
120120
expect(path.length).toBe(3);
121121
expect(scatter.chart.getXScale().scale(8) * width < path[0][1]).toBeTruthy();
122122

@@ -154,9 +154,9 @@ describe('scatter', () => {
154154
const { width } = scatter.chart;
155155
const pathGroup = scatter.chart
156156
.getComponents()
157-
.find((item) => item.type === 'annotation')
157+
.find((item) => item.type === 'annotation')!
158158
.component.cfg.group.cfg.children[0].getChildren();
159-
const { path } = pathGroup?.[0]?.cfg?.attrs;
159+
const { path = [] } = pathGroup?.[0]?.cfg?.attrs || {};
160160
expect(path.length).toBe(3);
161161
expect(scatter.chart.getXScale().scale(8) * width < path[0][1]).toBeTruthy();
162162

@@ -180,9 +180,9 @@ describe('scatter', () => {
180180
await delay(100);
181181
const pathGroup = scatter.chart
182182
.getComponents()
183-
.find((item) => item.type === 'annotation')
183+
.find((item) => item.type === 'annotation')!
184184
.component.cfg.group.cfg.children[0].getChildren();
185-
const { path } = pathGroup?.[0]?.cfg?.attrs;
185+
const { path = [] } = pathGroup?.[0]?.cfg?.attrs || {};
186186
expect(path.length).toBe(2); // linear
187187

188188
scatter.destroy();

__tests__/unit/plots/sunburst/treemap-spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ describe('treemap sunburst', () => {
6262
const geometry = sunburstPlot.chart.geometries[0];
6363

6464
expect(geometry.type).toBe('polygon');
65-
// @ts-ignore
6665
const {
66+
// @ts-ignore
6767
attributeOption: { color },
6868
coordinate,
6969
} = geometry;
@@ -105,8 +105,8 @@ describe('treemap sunburst', () => {
105105
sunburstPlot.render();
106106
const geometry = sunburstPlot.chart.geometries[0];
107107
expect(geometry.type).toBe('polygon');
108-
// @ts-ignore
109108
const {
109+
// @ts-ignore
110110
attributeOption: { color },
111111
coordinate,
112112
} = geometry;
@@ -155,8 +155,8 @@ describe('treemap sunburst', () => {
155155
sunburstPlot.render();
156156
const geometry = sunburstPlot.chart.geometries[0];
157157
expect(geometry.type).toBe('polygon');
158-
// @ts-ignore
159158
const {
159+
// @ts-ignore
160160
attributeOption: { color },
161161
coordinate,
162162
} = geometry;

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@
7373
"@commitlint/cli": "^8.2.0",
7474
"@commitlint/config-angular": "^8.2.0",
7575
"@types/jest": "^25.2.1",
76-
"@typescript-eslint/eslint-plugin": "^2.0.0",
77-
"@typescript-eslint/parser": "^2.0.0",
76+
"@typescript-eslint/eslint-plugin": "^5.54.1",
77+
"@typescript-eslint/parser": "^5.54.1",
7878
"antd": "^4.8.4",
7979
"babel-loader": "^8.1.0",
8080
"conventional-changelog-cli": "^2.0.34",
8181
"cross-env": "^7.0.2",
82-
"eslint": "^6.1.0",
83-
"eslint-config-prettier": "^6.0.0",
82+
"eslint": "^8.35.0",
83+
"eslint-config-prettier": "^8.7.0",
8484
"eslint-plugin-import": "^2.22.0",
85-
"eslint-plugin-prettier": "^3.1.0",
85+
"eslint-plugin-prettier": "^4.2.0",
8686
"generate-changelog": "^1.8.0",
8787
"husky": "^4.2.3",
8888
"jest": "^26.0.1",
@@ -101,7 +101,7 @@
101101
"rimraf": "^3.0.0",
102102
"ts-jest": "^25.4.0",
103103
"ts-loader": "^7.0.0",
104-
"typescript": "^3.5.3",
104+
"typescript": "^4",
105105
"webpack": "^4.44.2",
106106
"webpack-bundle-analyzer": "^3.9.0",
107107
"webpack-cli": "^3.3.7",

src/plots/bidirectional-bar/adaptor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function label(params: Params<BidirectionalBarOptions>): Params<BidirectionalBar
314314
if (typeof cfg.position === 'string') {
315315
cfg.position = positionMap[cfg.position];
316316
} else if (typeof cfg.position === 'function') {
317-
cfg.position = (...args) => positionMap[(cfg.position as Function).apply(this, args)];
317+
cfg.position = (...args) => positionMap[(cfg.position as any).apply(this, args)];
318318
}
319319
// 设置 textBaseline 默认值
320320
const textBaseline = leftLabelCfg.style?.textBaseline || 'bottom';

src/plots/sankey/layout.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type SankeyLayoutOutputData = {
6262
/**
6363
* 对齐方式的类型定义
6464
*/
65-
export type NodeAlign = keyof typeof ALIGN_METHOD | Function;
65+
export type NodeAlign = keyof typeof ALIGN_METHOD | ((...args: any[]) => any);
6666

6767
/**
6868
* 节点的 depth 自定义

src/utils/hierarchy/partition.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface Options {
2020
round?: boolean;
2121
ratio?: number;
2222
padding?: number;
23-
sort?: Function;
23+
sort?: (a: any, b: any) => any; // Function;
2424
as?: [string, string];
2525

2626
ignoreParentValue?: boolean;

0 commit comments

Comments
 (0)