Skip to content

Commit 7bcf57e

Browse files
committed
fix(types): fix types for vue < 2.7
1 parent ce3ba29 commit 7bcf57e

File tree

8 files changed

+96
-16
lines changed

8 files changed

+96
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.6.6
2+
3+
* Fixed types for Vue < 2.7.
4+
15
## 6.6.5
26

37
* Fixed type for `option` regressed in v6.6.2.

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center">Vue-ECharts</h1>
22

3-
<p align="center">Vue.js <sup>(v2/v3)</sup> component for Apache ECharts <sup>(v5)</sup>.</p>
3+
<p align="center">Vue.js <sup>(v2/v3)</sup> component for Apache ECharts <sup>(v5)</sup>.</p>
44
<p align="center"><a href="https://vue-echarts.dev/">View Demo →</a></p>
55
<p align="center"><a href="https:///pr.new/ecomfe/vue-echarts"><img alt="Open in Codeflow" src="https://developer.stackblitz.com/img/open_in_codeflow.svg" height="28"/></a> <a href="https://codesandbox.io/p/github/ecomfe/vue-echarts"><img alt="Edit in CodeSandbox" src="https://assets.codesandbox.io/github/button-edit-lime.svg" height="28"/></a></p>
66

@@ -23,17 +23,18 @@ Not ready yet? Read documentation for older versions [here →](https://github.c
2323

2424
### npm & ESM
2525

26-
```bash
27-
npm install echarts vue-echarts
26+
```sh
27+
npm i echarts vue-echarts
2828
```
2929

30-
To make `vue-echarts` work for _Vue 2_ (<2.7.0), you need to have `@vue/composition-api` installed:
30+
To make `vue-echarts` work for _Vue 2_ (<2.7.0), you need to have `@vue/composition-api` installed (`@vue/runtime-core` for TypeScript support):
3131

3232
```sh
3333
npm i @vue/composition-api
34+
npm i @vue/runtime-core # for TypeScript support
3435
```
3536

36-
If you are using _NuxtJS_ on top of _Vue 2_, you'll also need `@nuxtjs/composition-api`:
37+
If you are using _NuxtJS_ on top of _Vue 2_, you'll need `@nuxtjs/composition-api`:
3738

3839
```sh
3940
npm i @nuxtjs/composition-api
@@ -475,7 +476,7 @@ The following breaking changes are introduced in `vue-echarts@6`:
475476

476477
### Vue 2 support
477478

478-
- If you are using version prior to `[email protected]`, `@vue/composition-api` is required to be installed to use Vue-ECharts with Vue 2.
479+
- If you are using version prior to `[email protected]`, `@vue/composition-api` is required to be installed to use Vue-ECharts with Vue 2 (and also `@vue/runtime-core` for TypeScript support).
479480

480481
### Props
481482

@@ -500,7 +501,7 @@ The following breaking changes are introduced in `vue-echarts@6`:
500501

501502
## Local development
502503

503-
```bash
504+
```sh
504505
pnpm i
505506
pnpm serve
506507
```

README.zh-Hans.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center">Vue-ECharts</h1>
22

3-
<p align="center">Apache ECharts <sup>(v5)</sup> 的 Vue.js <sup>(v2/v3)</sup> 组件。</p>
3+
<p align="center">Apache ECharts <sup>(v5)</sup> 的 Vue.js <sup>(v2/v3)</sup> 组件。</p>
44
<p align="center"><a href="https://vue-echarts.dev/">查看 Demo →</a></p>
55
<p align="center"><a href="https:///pr.new/ecomfe/vue-echarts"><img alt="Open in Codeflow" src="https://developer.stackblitz.com/img/open_in_codeflow.svg" height="28"/></a> <a href="https://codesandbox.io/p/github/ecomfe/vue-echarts"><img alt="Edit in CodeSandbox" src="https://assets.codesandbox.io/github/button-edit-lime.svg" height="28"/></a></p>
66

@@ -23,17 +23,18 @@
2323

2424
### npm & ESM
2525

26-
```bash
27-
npm install echarts vue-echarts
26+
```sh
27+
npm i echarts vue-echarts
2828
```
2929

30-
要在 _Vue 2_(<2.7.0)下使用 `vue-echarts`,需要确保 `@vue/composition-api` 已经安装:
30+
要在 _Vue 2_(<2.7.0)下使用 `vue-echarts`,需要确保 `@vue/composition-api` 已经安装(TypeScript 支持还需要 `@vue/runtime-core`
3131

3232
```sh
3333
npm i @vue/composition-api
34+
npm i @vue/runtime-core # TypeScript 支持
3435
```
3536

36-
如果你在使用基于 _Vue 2__NuxtJS_那么还需要安装 `@nuxtjs/composition-api`
37+
如果你在使用基于 _Vue 2__NuxtJS_则需要安装 `@nuxtjs/composition-api`
3738

3839
```sh
3940
npm i @nuxtjs/composition-api
@@ -475,7 +476,7 @@ import { THEME_KEY } from 'vue-echarts'
475476
476477
### Vue 2 支持
477478
478-
- 要在 `vue@2.7.0` 之前的版本中使用 Vue-ECharts,必须安装 `@vue/composition-api`
479+
- 要在 `vue@2.7.0` 之前的版本中使用 Vue-ECharts,必须安装 `@vue/composition-api`(还需要安装 `@vue/runtime-core` 来支持 TypeScript)
479480
480481
### Prop
481482
@@ -500,7 +501,7 @@ import { THEME_KEY } from 'vue-echarts'
500501
501502
## 本地开发
502503
503-
```bash
504+
```sh
504505
pnpm i
505506
pnpm serve
506507
```

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-echarts",
3-
"version": "6.6.5",
3+
"version": "6.6.6",
44
"description": "Vue.js component for Apache ECharts.",
55
"author": "GU Yiling <[email protected]>",
66
"scripts": {
@@ -73,6 +73,7 @@
7373
},
7474
"peerDependencies": {
7575
"@vue/composition-api": "^1.0.5",
76+
"@vue/runtime-core": "^3.0.0",
7677
"echarts": "^5.4.1",
7778
"vue": "^2.6.12 || ^3.1.1"
7879
},
@@ -81,6 +82,9 @@
8182
"peerDependenciesMeta": {
8283
"@vue/composition-api": {
8384
"optional": true
85+
},
86+
"@vue/runtime-core": {
87+
"optional": true
8488
}
8589
},
8690
"repository": "https://github.com/ecomfe/vue-echarts.git",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/postinstall.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const packageFile = path.resolve(__dirname, "../package.json");
66

77
const typesPaths = {
88
3: "dist/index.d.ts",
9+
2.7: "dist/index.vue2-7.d.ts",
910
2: "dist/index.vue2.d.ts"
1011
};
1112

@@ -36,6 +37,8 @@ if (!Vue || typeof Vue.version !== "string") {
3637
);
3738
} else if (Vue.version.startsWith("3.")) {
3839
switchVersion(3);
40+
} else if (Vue.version.startsWith("2.7.")) {
41+
switchVersion(2.7);
3942
} else if (Vue.version.startsWith("2.")) {
4043
switchVersion(2);
4144
} else {

src/index.vue2.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-types */
2-
import type { Ref, DefineComponent } from "vue-demi";
2+
import type { DefineComponent } from "@vue/runtime-core";
3+
import type { Ref } from "vue-demi";
34
import type {
45
Option,
56
InitOptions,

src/index.vue2_7.d.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* eslint-disable @typescript-eslint/ban-types */
2+
import type { Ref, DefineComponent } from "vue-demi";
3+
import type {
4+
Option,
5+
InitOptions,
6+
UpdateOptions,
7+
EChartsType,
8+
Emits
9+
} from "./types";
10+
11+
declare const LOADING_OPTIONS_KEY = "ecLoadingOptions";
12+
declare const THEME_KEY = "ecTheme";
13+
declare const INIT_OPTIONS_KEY = "ecInitOptions";
14+
declare const UPDATE_OPTIONS_KEY = "ecUpdateOptions";
15+
16+
declare type ChartProps = {
17+
loading?: boolean;
18+
loadingOptions?: Record<string, unknown>;
19+
autoresize?: boolean;
20+
option?: Option;
21+
theme?: string | Record<string, unknown>;
22+
initOptions?: InitOptions;
23+
updateOptions?: UpdateOptions;
24+
group?: string;
25+
manualUpdate?: boolean;
26+
};
27+
28+
type MethodNames =
29+
| "getWidth"
30+
| "getHeight"
31+
| "getDom"
32+
| "getOption"
33+
| "resize"
34+
| "dispatchAction"
35+
| "convertToPixel"
36+
| "convertFromPixel"
37+
| "containPixel"
38+
| "getDataURL"
39+
| "getConnectedDataURL"
40+
| "appendData"
41+
| "clear"
42+
| "isDisposed"
43+
| "dispose"
44+
| "setOption";
45+
46+
declare type ChartMethods = Pick<EChartsType, MethodNames>;
47+
48+
declare const Chart: DefineComponent<
49+
ChartProps,
50+
{
51+
root: Ref<HTMLElement | undefined>;
52+
chart: Ref<EChartsType | undefined>;
53+
},
54+
{},
55+
{},
56+
ChartMethods,
57+
{},
58+
{},
59+
Emits
60+
>;
61+
62+
export default Chart;
63+
export { INIT_OPTIONS_KEY, LOADING_OPTIONS_KEY, THEME_KEY, UPDATE_OPTIONS_KEY };

0 commit comments

Comments
 (0)