如果类型定义说输入可以是
null或则产生错误
HTMLInputElement
您可以
"strict": false在
tsconfig.json
或者您可以强制输入为
HTMLInputElement输入
<input ref={thisInput => (this.textInput = thisInput as HTMLInputElement)} type="text" className="form-control" placeholder="Search" />这种方法也是有效的(使用定值分配断言(打字稿> =
2.7))
<input ref={thisInput => (this.textInput = thisInput!)} type="text" className="form-control" placeholder="Search" />


