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
·
在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);
更多推荐
已为社区贡献3条内容
所有评论(0)