对象在KeyboardEvent

时间:2019-07-27 22:21:52

标签: javascript reactjs typescript types keyboard-events

在与打字稿进行互动的Object is of type 'unknown'.ts(2571) 上,我收到KeyboardEvent的打字稿错误。

handleKeyDown = (e: KeyboardEvent<HTMLFormElement>) => {
  if (e.key === 'Enter' && (e.ctrlKey || e.metaKey) && this.formRef.current) {
    const submitButton = this.formRef.current.querySelector(
      'button:not([type]), button[type="submit"], input[type="submit"]',
    );
    if (submitButton) submitButton.click();
    e.preventDefault();
  }
};

并且错误出现在this.formRef.current行的const submitButton = this.formRef.current.querySelector

为什么此错误出现在this.formRef.current行的if (e.key === 'Enter' && (e.ctrlKey || e.metaKey) && this.formRef.current) {中而不是?

0 个答案:

没有答案