ts项目中报错
在typescript项目中,初始化echarts图表
const chart = echarts.init(document.getElementById('chart'));
报错
Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'.
Type 'null' is not assignable to type 'HTMLElement'.
解决方法:增加类型断言(Type Assertion)
const HTMLElement = document.getElementById("chart") as HTMLElement;
const chart = echarts.init(HTMLElement );

本文介绍在TypeScript项目中使用ECharts初始化图表时遇到的类型错误问题,并提供了解决方案,即通过类型断言确保获取到的元素符合ECharts初始化的要求。
5522

被折叠的 条评论
为什么被折叠?



