TypeScript——不能将类型“HTMLElement | null”分配给类型“HTMLElement”

Posted 微个日光日

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeScript——不能将类型“HTMLElement | null”分配给类型“HTMLElement”相关的知识,希望对你有一定的参考价值。

针对不能将类型“htmlElement | null”分配给类型“HTMLElement” 错误,可根据实际情况使用!进行处理或者使用as进行断言;

出错代码如下:

出错原因:可能获取不到container

解决办法:

1. 使用!

2. 使用 as

 

 

以上是关于TypeScript——不能将类型“HTMLElement | null”分配给类型“HTMLElement”的主要内容,如果未能解决你的问题,请参考以下文章