为什么已经为useRef指定了泛型HTMLInputElement,TS还是报ts(2531)

 const logEditorRef = useRef<HTMLInputElement>(null);
  
  const resizeEditor = () => {
    logEditorRef.current.style.height = document.body.clientHeight - 86 + 'px';
  };

关键代码如上,typescript环境下,提示ts(2531)错误

image.png

阅读 1.8k
1 个回答

加个非空判断试试

if(logEditorRef){
     ....
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题