Export `ECharts` class in TypeScript
See original GitHub issueVersion
5.0
What problem does this feature solve?
The init
function returns a class of type ECharts
. This works fine as long as you use the chart variable right after initalization.
import {init, EChartsOption} from "echarts";
...
export class BaseChart {
initChart() {
const chart = init(nativeElement);
// do something else with the chart.
}
}
But all typings get lost, when you want to pass the chart around (e.g. for updating data later on)
import {init, EChartsOption} from "echarts";
...
export class BaseChart {
const chart: ECharts; // <--- This does not work. You can it make `any`, but then all typings are lost;
initChart() {
this.chart = init(nativeElement);
// do something else with the chart.
}
}
The TypeScript definitions do not export the ECharts
class
import {ECharts} from "echarts" // <---- This is not possible
Edit
Using EChartsType
which is extending ECharts
does not work too.
import {init, EChartsOption} from "echarts";
import {EChartsType} from "echarts/lib/echarts";
...
export class BaseChart {
initChart() {
const chart: EChartsType = init(nativeElement);
// This doesn't work too
// TS2322: Type 'ECharts' is not assignable to type 'EChartsType'.
// Types have separate declarations of a private property '_zr'.
}
}
What does the proposed API look like?
Extend the exports in TypeScript. Something like this:
export { ECharts, EChartsFullOption as EChartsOption, connect, disConnect, dispose, getInstanceByDom, getInstanceById, getMap, init, registerLocale, registerMap, registerTheme };
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Export `ECharts` class in TypeScript · Issue #13755
The TypeScript definitions do not export the ECharts class. import {ECharts} from "echarts" // <---- This is not possible.
Read more >Using Apache ECharts with React and TypeScript
If you happen to use Apache ECharts, this feed may help you integrate it with your React + TypeScript codebase.
Read more >Is it possible to use ECharts Baidu with Angular 2 and ...
They use require as a function but typescript has its own require. ... export class AdvertReportComponent implements OnInit { echarts: any ...
Read more >ngx-echarts
Start using ngx-echarts in your project by running `npm i ngx-echarts`. ... TypeScript icon, indicating that this package has built-in type ...
Read more >Using ECharts with TypeScript - 羡辙杂俎 - Wenli Zhang
Now, echarts can be accessed in your TypeScript file. ... export class Page3 { constructor() { console.log(echarts); // works here } } ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Further to your comment, we are relying on the other types like BarSeriesOption, ChartDataset, etc. This change in v5 will result in losing all of the typings in our code base. Also, as a result of not exporting them none of the fields in the EchartsOptions have any types. Please consider exporting them all
In my case the workaround above does not work but the codes below worked around
echarts@v5.0.0 TypeScript@v4.0.5