Skip to content

fix(dom): accept typed arrays in DOMMatrix constructor - #2558

Open
Magicapple (magicapple123) wants to merge 3 commits into
microsoft:mainfrom
magicapple123:fix/dommatrix-typedarray-constructor
Open

Magicapple (magicapple123) wants to merge 3 commits into
microsoft:mainfrom
magicapple123:fix/dommatrix-typedarray-constructor

Conversation

@magicapple123

Copy link
Copy Markdown

Fixes microsoft/TypeScript#60862

Summary

  • new DOMMatrix() and new DOMMatrixReadOnly() accept Float32Array / Float64Array in all browsers, and MDN documents those overloads, but the generated lib.dom.d.ts only allows string | number[].
  • Root cause: the current geometry spec IDL declares the constructor as (DOMString or sequence<unrestricted double>) only — typed-array support now lives behind the static fromFloat32Array / fromFloat64Array methods in the spec text, while browsers still accept them in the constructor.
  • Since the DOM files are generated from the (updated) webref IDL, browser-tested behavior needs to be restored via inputfiles/overridingTypes.jsonc.

Changes

  • inputfiles/overridingTypes.jsonc: constructor override for DOMMatrix and DOMMatrixReadOnly, restoring string | number[] | Float32Array | Float64Array for the init parameter.
  • unittests/files/dommatrix.ts: positive cases for typed arrays plus the pre-existing overloads.
  • Baselines updated (8 lines across dom / webworker / serviceworker / sharedworker — DOMMatrix is Exposed=(Window,Worker)).

Testing

  • node ./src/build.ts regenerates the expected signatures.
  • node ./unittests/index.js passes, including the new dommatrix.ts cases.
  • eslint src deploy/*.js scripts passes.

The DOMMatrix and DOMMatrixReadOnly constructors accept Float32Array and
Float64Array in all browsers (documented on MDN), but the current geometry
spec IDL lists only 'sequence<unrestricted double>' for the constructor, so
the generated lib.dom.d.ts loses typed array support.

Add constructor overrides restoring 'string | number[] | Float32Array |
Float64Array' for both interfaces.

Fixes microsoft/TypeScript#60862
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR!

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

Comment thread inputfiles/overridingTypes.jsonc Outdated
"param": [
{
"name": "init",
"overrideType": "string | number[] | Float32Array | Float64Array"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use additionaltype?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — switched to additionalTypes in ef34ea0. Besides keeping the IDL-derived members intact, it also lets the generator emit the version-appropriate syntax: Float32Array<ArrayBuffer> for the current target (matching the existing fromFloat32Array signatures) and plain Float32Array for the ts5.5/ts5.6 targets, which a hardcoded overrideType string could not do. Thanks!

Following review feedback: appending 'Float32Array' / 'Float64Array' via
additionalTypes keeps the IDL-derived union members intact and lets the
generator emit the version-appropriate syntax (Float32Array<ArrayBuffer>
for the current target, plain Float32Array for the ts5.5/ts5.6 targets).
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.

lib.dom: DOMatrix constructor accepts TypedArrays, not only Arrays.

2 participants