Performance 接口中缺少 onresourcetimingbufferfull 事件
Missing onresourcetimingbufferfull event from Performance interface
资源计时 API 有类似 onresourcetimegingbufferfull 的事件,当达到 150(默认)资源的限制时会被触发。
https://www.w3.org/TR/resource-timing-1/#extensions-performance-interface
lib.d.ts 文件 https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts 中的性能接口没有定义 onresourcetimingbufferfull 事件。有什么办法可以实现吗?
当然可以!您可以简单地在自己的代码中扩充 Performance
接口:
// this does not overwrite `Performance`, it just augments it
interface Performance {
onresourcetimingbufferfull: (e: Event) => any;
// and/or perhaps something like
addEventListener(type: "resourcetimingbufferfull", handler: (e: Event) => any): void;
// in versions of TS before 2.0, you'll need to add this line also:
addEventListener(type: string, handler: (e: Event) => any): void;
}
function bufferFull(e: Event) {
console.log("WARNING: Resource Timing Buffer is FULL!");
performance.setResourceTimingBufferSize(200);
}
performance.onresourcetimingbufferfull = bufferFull;
performance.addEventListener("resourcetimingbufferfull", bufferFull);
我找不到 the resourcetimingbufferfull
event carried any special payload,所以最简单的方法就是将其键入为常规的旧 Event
。
资源计时 API 有类似 onresourcetimegingbufferfull 的事件,当达到 150(默认)资源的限制时会被触发。 https://www.w3.org/TR/resource-timing-1/#extensions-performance-interface
lib.d.ts 文件 https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts 中的性能接口没有定义 onresourcetimingbufferfull 事件。有什么办法可以实现吗?
当然可以!您可以简单地在自己的代码中扩充 Performance
接口:
// this does not overwrite `Performance`, it just augments it
interface Performance {
onresourcetimingbufferfull: (e: Event) => any;
// and/or perhaps something like
addEventListener(type: "resourcetimingbufferfull", handler: (e: Event) => any): void;
// in versions of TS before 2.0, you'll need to add this line also:
addEventListener(type: string, handler: (e: Event) => any): void;
}
function bufferFull(e: Event) {
console.log("WARNING: Resource Timing Buffer is FULL!");
performance.setResourceTimingBufferSize(200);
}
performance.onresourcetimingbufferfull = bufferFull;
performance.addEventListener("resourcetimingbufferfull", bufferFull);
我找不到 the resourcetimingbufferfull
event carried any special payload,所以最简单的方法就是将其键入为常规的旧 Event
。