我试图在这样的反应组件中的函数中声明事件的类型,但是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 回答
您正在寻找的类型名为
Event
.window.event
是window
对象的成员,其类型为Event
;它's not the type itself, hence why you'当您尝试将其用作一个时出现错误 .