Skip to content

fix: type observer callback entries and box sizes as non-empty tuples#2515

Open
homayounmmdy wants to merge 1 commit into
microsoft:mainfrom
homayounmmdy:fix/observer-callbacks-non-empty-tuples
Open

fix: type observer callback entries and box sizes as non-empty tuples#2515
homayounmmdy wants to merge 1 commit into
microsoft:mainfrom
homayounmmdy:fix/observer-callbacks-non-empty-tuples

Conversation

@homayounmmdy

Copy link
Copy Markdown

This PR addresses microsoft/TypeScript#61691.

The Problem:
The current Web IDL spec types observer callback parameters (like entries in ResizeObserverCallback) as standard arrays (T[]). However, the browser specification guarantees that these callbacks are only ever invoked when there is at least one observation. This forces developers to use unnecessary non-null assertions (!) or runtime checks for a state that is theoretically impossible.

The Solution:
This PR adds manual overrides in overridingTypes.jsonc to enforce a non-empty tuple type ([T, ...T[]]) for:

  • ResizeObserverCallback
  • IntersectionObserverCallback
  • MutationCallback
  • ResizeObserverEntry's contentBoxSize, borderBoxSize, and devicePixelContentBoxSize properties.

Verification:
Ran npm run generate and verified the output in baselines/dom.generated.d.ts reflects the correct non-empty tuple types without breaking the build.

- 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
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@homayounmmdy

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant