首页 文章

如何设置窗口事件的类型?

提问于
浏览
0

我试图在这样的反应组件中的函数中声明事件的类型,但是typescript抱怨 Cannot find namespace Window 并且如果我小写 window 则没有区别

handleChange = (event: Window.Event) => {
        console.log("event");

  }

TypeScript中的Window接口具有这些(和其他属性)

interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64 {
    animationStartTime: number;
    applicationCache: ApplicationCache;
    clientInformation: Navigator;
    closed: boolean;
    crypto: Crypto;
    defaultStatus: string;
    devicePixelRatio: number;
    doNotTrack: string;
    document: Document;
    event: Event;

如何设置该事件的类型?

1 回答

  • 0

    您正在寻找的类型名为 Event . window.eventwindow 对象的成员,其类型为 Event ;它's not the type itself, hence why you'当您尝试将其用作一个时出现错误 .

相关问题