fix(dom): accept typed arrays in DOMMatrix constructor - #2558
Open
Magicapple (magicapple123) wants to merge 3 commits into
Open
Magicapple (magicapple123) wants to merge 3 commits into
Magicapple (magicapple123) wants to merge 3 commits into
Conversation
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
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. |
| "param": [ | ||
| { | ||
| "name": "init", | ||
| "overrideType": "string | number[] | Float32Array | Float64Array" |
Contributor
There was a problem hiding this comment.
Why not use additionaltype?
There was a problem hiding this comment.
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).
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.
Fixes microsoft/TypeScript#60862
Summary
new DOMMatrix()andnew DOMMatrixReadOnly()acceptFloat32Array/Float64Arrayin all browsers, and MDN documents those overloads, but the generatedlib.dom.d.tsonly allowsstring | number[].(DOMString or sequence<unrestricted double>)only — typed-array support now lives behind the staticfromFloat32Array/fromFloat64Arraymethods in the spec text, while browsers still accept them in the constructor.inputfiles/overridingTypes.jsonc.Changes
inputfiles/overridingTypes.jsonc: constructor override forDOMMatrixandDOMMatrixReadOnly, restoringstring | number[] | Float32Array | Float64Arrayfor theinitparameter.unittests/files/dommatrix.ts: positive cases for typed arrays plus the pre-existing overloads.dom/webworker/serviceworker/sharedworker— DOMMatrix isExposed=(Window,Worker)).Testing
node ./src/build.tsregenerates the expected signatures.node ./unittests/index.jspasses, including the newdommatrix.tscases.eslint src deploy/*.js scriptspasses.