Argument of type ‘HTMLElement | null‘ is not assignable to parameter of type ‘HTMLElement‘. Type ‘
在vue3.0+typescript+echarts5.0项目中,初始化图表,
public myChart = echarts.init(document.getElementById("main"));
控制台出现以下报错
Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'.
Type 'null' is not assignable to type 'HTMLElement'.
解决方法:增加类型断言(Type Assertion)
public main: HTMLElement = document.getElementById("main") as HTMLElement;
public myChart = echarts.init(this.main);
还没有评论,来说两句吧...