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 );