首页 > 解决方案 > 传递给 IE 11 特定 deactivate 事件的侦听器的事件有什么类型?

问题描述

这是我的代码中的常见事件。我知道调用 onChange 事件的类型。

private onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    ...
};

但是传递给这个事件监听器的事件是什么类型的呢?

// Since blur is asynchronous in IE11 we can't guarantee that a change
// will be saved onBlur when changing component model. The IE exclusive
// `deactivate` event triggers before any other click handlers.

this.inputRef.current!.addEventListener('deactivate', this.onDeactivate);

private onDeactivate = (e: any) => {
    ...
};

标签: typescriptinternet-explorer-11

解决方案


this.inputRef.current!.addEventListener('deactivate', this.onDeactivate);if currentis of type HTMLInputElementthene是 type Event

如何弄清楚

添加一个本地函数并将鼠标悬停在参数上以查看其推断类型。

在此处输入图像描述

这是 react onChange 的类型(您已经知道):

在此处输入图像描述


推荐阅读