Skip to content

Commit 259665c

Browse files
committed
types: improve typings for vue 2
1 parent 5e51ab1 commit 259665c

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.3
2+
3+
* Improved typings for Vue 2 version.
4+
15
## 6.0.2
26

37
* Make `notMerge` option still respect `update-options`.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "vue-echarts",
3-
"version": "6.0.2",
3+
"version": "6.0.3",
44
"description": "Vue.js component for Apache ECharts.",
55
"author": "GU Yiling <[email protected]>",
66
"scripts": {
77
"serve": "vue-cli-service serve",
8-
"build": "npm run docs && rimraf dist && rollup -c rollup.config.js && cp src/index.vue2.d.ts dist",
8+
"build": "npm run docs && rimraf dist && rollup -c rollup.config.js",
99
"lint": "vue-cli-service lint",
1010
"build:demo": "vue-cli-service build",
1111
"docs": "node -r esm ./scripts/docs.js",

rollup.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ const options = [
9797
file: "dist/index.d.ts",
9898
format: "es"
9999
}
100+
},
101+
{
102+
input: "src/index.vue2.d.ts",
103+
plugins: [dts()],
104+
output: {
105+
file: "dist/index.vue2.d.ts",
106+
format: "es"
107+
}
100108
}
101109
];
102110

src/index.vue2.d.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
1+
/* eslint-disable @typescript-eslint/ban-types */
2+
import { DefineComponent } from "@vue/runtime-dom";
3+
import { Ref } from "@vue/composition-api";
4+
import { Option, InitOptions, UpdateOptions, EChartsType } from "./types";
5+
26
declare const LOADING_OPTIONS_KEY = "ecLoadingOptions";
37
declare const THEME_KEY = "ecTheme";
48
declare const INIT_OPTIONS_KEY = "ecInitOptions";
59
declare const UPDATE_OPTIONS_KEY = "ecUpdateOptions";
610

7-
declare const _default: any;
11+
declare type ChartProps = {
12+
loading?: boolean;
13+
loadingOptions?: Record<string, unknown>;
14+
autoresize?: boolean;
15+
option?: Option;
16+
theme?: string | Record<string, unknown>;
17+
initOptions?: InitOptions;
18+
updateOptions?: UpdateOptions;
19+
group?: string;
20+
manualUpdate?: boolean;
21+
};
22+
23+
type MethodNames =
24+
| "getWidth"
25+
| "getHeight"
26+
| "getDom"
27+
| "getOption"
28+
| "resize"
29+
| "dispatchAction"
30+
| "convertToPixel"
31+
| "convertFromPixel"
32+
| "containPixel"
33+
| "getDataURL"
34+
| "getConnectedDataURL"
35+
| "appendData"
36+
| "clear"
37+
| "isDisposed"
38+
| "dispose"
39+
| "setOption";
40+
41+
declare type ChartMethods = Pick<EChartsType, MethodNames>;
42+
43+
declare const Chart: DefineComponent<
44+
ChartProps,
45+
{
46+
root: Ref<HTMLElement | undefined>;
47+
chart: Ref<EChartsType | undefined>;
48+
},
49+
{},
50+
{},
51+
ChartMethods
52+
>;
853

9-
export default _default;
54+
export default Chart;
1055
export { INIT_OPTIONS_KEY, LOADING_OPTIONS_KEY, THEME_KEY, UPDATE_OPTIONS_KEY };

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import { init, SetOptionOpts } from "echarts/core";
32
import { Ref } from "vue";
43

0 commit comments

Comments
 (0)