typescript 找不到空闲检测器

tf7tbtn2  于 2023-03-04  发布在  TypeScript
关注(0)|答案(1)|浏览(108)

我想使用IdleDetector,但是Typescript没有类型,如果说Cannot find name 'IdleDetector',我该怎么办?

vs3odd8k

vs3odd8k1#

您可以将以下内容添加到global.d.ts

interface IdleDetector {
    addEventListener(type: "change", listener: (this: IdleDetector, ev: { userState: "active" | "idle", screenState: "locked" | "unlocked" }) => unknown, options?: boolean | AddEventListenerOptions): void;
    start(options: { threshold: number }): Promise<void>;
    screenState: "locked" | "unlocked";
    userState: "active" | "idle";
}

declare const IdleDetector: {
    new(): IdleDetector;
    requestPermission(): Promise<"granted" | "denied">;
};

它不是100%正确,但对我来说已经足够好了。

相关问题