fix: type observer callback entries and box sizes as non-empty tuples#2515
Open
homayounmmdy wants to merge 1 commit into
Open
fix: type observer callback entries and box sizes as non-empty tuples#2515homayounmmdy wants to merge 1 commit into
homayounmmdy wants to merge 1 commit into
Conversation
- 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
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. |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses microsoft/TypeScript#61691.
The Problem:
The current Web IDL spec types observer callback parameters (like
entriesinResizeObserverCallback) 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.jsoncto enforce a non-empty tuple type ([T, ...T[]]) for:ResizeObserverCallbackIntersectionObserverCallbackMutationCallbackResizeObserverEntry'scontentBoxSize,borderBoxSize, anddevicePixelContentBoxSizeproperties.Verification:
Ran
npm run generateand verified the output inbaselines/dom.generated.d.tsreflects the correct non-empty tuple types without breaking the build.