Skip to content

Commit

Permalink
implement WeakRef types
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-lebeau committed May 15, 2024
1 parent 7ed6dbf commit 7b89929
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/core/src/browser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ export interface VisualViewport extends EventTarget {
): void
}

export interface WeakRef<T extends object> {
readonly [Symbol.toStringTag]: 'WeakRef'

deref(): T | undefined
}

export interface WeakRefConstructor {
readonly prototype: WeakRef<any>

new <T extends object>(target: T): WeakRef<T>
}

// Those are native API types that are not official supported by TypeScript yet

export interface CookieStore extends EventTarget {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"sourceMap": true,

"types": [],
"lib": ["ES2022", "DOM"],
"lib": ["ES2016", "DOM"],

"paths": {
"@datadog/browser-core": ["./packages/core/src"],
Expand Down

0 comments on commit 7b89929

Please sign in to comment.