From 7b899294b68a27900effa0dd86d1d941323107c0 Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Wed, 15 May 2024 15:51:29 +0200 Subject: [PATCH] implement WeakRef types --- packages/core/src/browser/types.ts | 12 ++++++++++++ .../view/viewMetrics/trackCumulativeLayoutShift.ts | 3 +++ tsconfig.base.json | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/core/src/browser/types.ts b/packages/core/src/browser/types.ts index 54f09932b7..2dc0970a26 100644 --- a/packages/core/src/browser/types.ts +++ b/packages/core/src/browser/types.ts @@ -39,6 +39,18 @@ export interface VisualViewport extends EventTarget { ): void } +export interface WeakRef { + readonly [Symbol.toStringTag]: 'WeakRef' + + deref(): T | undefined +} + +export interface WeakRefConstructor { + readonly prototype: WeakRef + + new (target: T): WeakRef +} + // Those are native API types that are not official supported by TypeScript yet export interface CookieStore extends EventTarget {} diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts b/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts index a19a165342..9c9de27dce 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts @@ -1,5 +1,6 @@ import { round, find, ONE_SECOND, noop } from '@datadog/browser-core' import type { RelativeTime } from '@datadog/browser-core' +import type { WeakRef, WeakRefConstructor } from 'packages/core/src/browser/types' import { isElementNode } from '../../../browser/htmlDomUtils' import type { LifeCycle } from '../../lifeCycle' import { LifeCycleEventType } from '../../lifeCycle' @@ -13,6 +14,8 @@ export interface CumulativeLayoutShift { targetSelector?: string } +declare const WeakRef: WeakRefConstructor + /** * Track the cumulative layout shifts (CLS). * Layout shifts are grouped into session windows. diff --git a/tsconfig.base.json b/tsconfig.base.json index 747cb83e7d..409a6763f4 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -11,7 +11,7 @@ "sourceMap": true, "types": [], - "lib": ["ES2022", "DOM"], + "lib": ["ES2016", "DOM"], "paths": { "@datadog/browser-core": ["./packages/core/src"],