How to avoid typescript error: Property 'innerHTML' does not exist on type 'Element'

后端 未结 6 2003
时光说笑
时光说笑 2020-12-16 09:14

I\'m trying to place some HTML inside a specific div. When I try this in typescript I get this error: Property \'innerHTML\' does not exist on type \'Element\'

6条回答
  •  不知归路
    2020-12-16 09:54

    Use a type assertion to placate the compiler:

    let myContainer =  document.querySelector("#myDiv");
    myContainer.innerHTML = '

    Test

    ';

提交回复
热议问题