From 40b1f1c5bb1f39162fa50a0f3d1aab26e1c1c8f9 Mon Sep 17 00:00:00 2001 From: Homayoun Date: Tue, 21 Jul 2026 21:02:51 +0330 Subject: [PATCH] fix: type observer callback entries and box sizes as non-empty tuples - Updates ResizeObserverCallback, IntersectionObserverCallback, and MutationCallback to use [T, ...T[]] instead of T[]. - Updates ResizeObserverEntry contentBoxSize, borderBoxSize, and devicePixelContentBoxSize to be non-empty readonly tuples. - Rationale: Browser specs guarantee these callbacks are only invoked when there is at least one observation, making the empty array case impossible at runtime. - References: microsoft/TypeScript#61691 --- baselines/dom.generated.d.ts | 10 +++---- baselines/ts5.5/dom.generated.d.ts | 10 +++---- baselines/ts5.6/dom.generated.d.ts | 10 +++---- baselines/ts5.9/dom.generated.d.ts | 10 +++---- inputfiles/overridingTypes.jsonc | 47 ++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 20 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index a9f596a9f..b3f460775 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -31257,13 +31257,13 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/borderBoxSize) */ - readonly borderBoxSize: ReadonlyArray; + readonly borderBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentBoxSize`** read-only property of the ResizeObserverEntry interface returns an array containing the new content box size of the observed element when the callback is run. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/contentBoxSize) */ - readonly contentBoxSize: ReadonlyArray; + readonly contentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentRect`** read-only property of the ResizeObserverEntry interface returns a DOMRectReadOnly object containing the new size of the observed element when the callback is run. Note that this is better supported than ResizeObserverEntry.borderBoxSize or ResizeObserverEntry.contentBoxSize, but it is left over from an earlier implementation of the Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future versions. * @@ -31275,7 +31275,7 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/devicePixelContentBoxSize) */ - readonly devicePixelContentBoxSize: ReadonlyArray; + readonly devicePixelContentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`target`** read-only property of the ResizeObserverEntry interface returns a reference to the Element or SVGElement that is being observed. * @@ -43836,7 +43836,7 @@ interface MediaSessionActionHandler { } interface MutationCallback { - (mutations: MutationRecord[], observer: MutationObserver): void; + (mutations: [MutationRecord, ...MutationRecord[]], observer: MutationObserver): void; } interface NavigationInterceptHandler { @@ -43892,7 +43892,7 @@ interface ReportingObserverCallback { } interface ResizeObserverCallback { - (entries: ResizeObserverEntry[], observer: ResizeObserver): void; + (entries: [ResizeObserverEntry, ...ResizeObserverEntry[]], observer: ResizeObserver): void; } interface SchedulerPostTaskCallback { diff --git a/baselines/ts5.5/dom.generated.d.ts b/baselines/ts5.5/dom.generated.d.ts index 30ad8bd55..7245146a2 100644 --- a/baselines/ts5.5/dom.generated.d.ts +++ b/baselines/ts5.5/dom.generated.d.ts @@ -31233,13 +31233,13 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/borderBoxSize) */ - readonly borderBoxSize: ReadonlyArray; + readonly borderBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentBoxSize`** read-only property of the ResizeObserverEntry interface returns an array containing the new content box size of the observed element when the callback is run. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/contentBoxSize) */ - readonly contentBoxSize: ReadonlyArray; + readonly contentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentRect`** read-only property of the ResizeObserverEntry interface returns a DOMRectReadOnly object containing the new size of the observed element when the callback is run. Note that this is better supported than ResizeObserverEntry.borderBoxSize or ResizeObserverEntry.contentBoxSize, but it is left over from an earlier implementation of the Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future versions. * @@ -31251,7 +31251,7 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/devicePixelContentBoxSize) */ - readonly devicePixelContentBoxSize: ReadonlyArray; + readonly devicePixelContentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`target`** read-only property of the ResizeObserverEntry interface returns a reference to the Element or SVGElement that is being observed. * @@ -43810,7 +43810,7 @@ interface MediaSessionActionHandler { } interface MutationCallback { - (mutations: MutationRecord[], observer: MutationObserver): void; + (mutations: [MutationRecord, ...MutationRecord[]], observer: MutationObserver): void; } interface NavigationInterceptHandler { @@ -43866,7 +43866,7 @@ interface ReportingObserverCallback { } interface ResizeObserverCallback { - (entries: ResizeObserverEntry[], observer: ResizeObserver): void; + (entries: [ResizeObserverEntry, ...ResizeObserverEntry[]], observer: ResizeObserver): void; } interface SchedulerPostTaskCallback { diff --git a/baselines/ts5.6/dom.generated.d.ts b/baselines/ts5.6/dom.generated.d.ts index 4f08212b7..db989b8fa 100644 --- a/baselines/ts5.6/dom.generated.d.ts +++ b/baselines/ts5.6/dom.generated.d.ts @@ -31254,13 +31254,13 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/borderBoxSize) */ - readonly borderBoxSize: ReadonlyArray; + readonly borderBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentBoxSize`** read-only property of the ResizeObserverEntry interface returns an array containing the new content box size of the observed element when the callback is run. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/contentBoxSize) */ - readonly contentBoxSize: ReadonlyArray; + readonly contentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentRect`** read-only property of the ResizeObserverEntry interface returns a DOMRectReadOnly object containing the new size of the observed element when the callback is run. Note that this is better supported than ResizeObserverEntry.borderBoxSize or ResizeObserverEntry.contentBoxSize, but it is left over from an earlier implementation of the Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future versions. * @@ -31272,7 +31272,7 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/devicePixelContentBoxSize) */ - readonly devicePixelContentBoxSize: ReadonlyArray; + readonly devicePixelContentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`target`** read-only property of the ResizeObserverEntry interface returns a reference to the Element or SVGElement that is being observed. * @@ -43833,7 +43833,7 @@ interface MediaSessionActionHandler { } interface MutationCallback { - (mutations: MutationRecord[], observer: MutationObserver): void; + (mutations: [MutationRecord, ...MutationRecord[]], observer: MutationObserver): void; } interface NavigationInterceptHandler { @@ -43889,7 +43889,7 @@ interface ReportingObserverCallback { } interface ResizeObserverCallback { - (entries: ResizeObserverEntry[], observer: ResizeObserver): void; + (entries: [ResizeObserverEntry, ...ResizeObserverEntry[]], observer: ResizeObserver): void; } interface SchedulerPostTaskCallback { diff --git a/baselines/ts5.9/dom.generated.d.ts b/baselines/ts5.9/dom.generated.d.ts index 9bccf9a99..34998d6b8 100644 --- a/baselines/ts5.9/dom.generated.d.ts +++ b/baselines/ts5.9/dom.generated.d.ts @@ -31254,13 +31254,13 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/borderBoxSize) */ - readonly borderBoxSize: ReadonlyArray; + readonly borderBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentBoxSize`** read-only property of the ResizeObserverEntry interface returns an array containing the new content box size of the observed element when the callback is run. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/contentBoxSize) */ - readonly contentBoxSize: ReadonlyArray; + readonly contentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`contentRect`** read-only property of the ResizeObserverEntry interface returns a DOMRectReadOnly object containing the new size of the observed element when the callback is run. Note that this is better supported than ResizeObserverEntry.borderBoxSize or ResizeObserverEntry.contentBoxSize, but it is left over from an earlier implementation of the Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future versions. * @@ -31272,7 +31272,7 @@ interface ResizeObserverEntry { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ResizeObserverEntry/devicePixelContentBoxSize) */ - readonly devicePixelContentBoxSize: ReadonlyArray; + readonly devicePixelContentBoxSize: readonly [ResizeObserverSize, ...ResizeObserverSize[]]; /** * The **`target`** read-only property of the ResizeObserverEntry interface returns a reference to the Element or SVGElement that is being observed. * @@ -43833,7 +43833,7 @@ interface MediaSessionActionHandler { } interface MutationCallback { - (mutations: MutationRecord[], observer: MutationObserver): void; + (mutations: [MutationRecord, ...MutationRecord[]], observer: MutationObserver): void; } interface NavigationInterceptHandler { @@ -43889,7 +43889,7 @@ interface ReportingObserverCallback { } interface ResizeObserverCallback { - (entries: ResizeObserverEntry[], observer: ResizeObserver): void; + (entries: [ResizeObserverEntry, ...ResizeObserverEntry[]], observer: ResizeObserver): void; } interface SchedulerPostTaskCallback { diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index cb40ea0a0..6a7e0328e 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -254,6 +254,38 @@ "overrideType": "T" } } + }, + "ResizeObserverCallback": { + "signature": { + "0": { + "param": [ + { + "name": "entries", + "overrideType": "[ResizeObserverEntry, ...ResizeObserverEntry[]]" + }, + { + "name": "observer", + "overrideType": "ResizeObserver" + } + ] + } + } + }, + "MutationCallback": { + "signature": { + "0": { + "param": [ + { + "name": "mutations", + "overrideType": "[MutationRecord, ...MutationRecord[]]" + }, + { + "name": "observer", + "overrideType": "MutationObserver" + } + ] + } + } } } }, @@ -2861,6 +2893,21 @@ "TrustedTypePolicyFactory": { "exposed": "" }, + "ResizeObserverEntry": { + "properties": { + "property": { + "contentBoxSize": { + "overrideType": "readonly [ResizeObserverSize, ...ResizeObserverSize[]]" + }, + "borderBoxSize": { + "overrideType": "readonly [ResizeObserverSize, ...ResizeObserverSize[]]" + }, + "devicePixelContentBoxSize": { + "overrideType": "readonly [ResizeObserverSize, ...ResizeObserverSize[]]" + } + } + } + } } }, "dictionaries": {