Add IntegerTypedArray type and use it for crypto.getRandomValues - #64343
Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
Conversation
Copilot started work on behalf of
Ryan Cavanaugh (RyanCavanaugh)
September 19, 2026 03:04
View session
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix IntegerTypedArray type for crypto.getRandomValues
Add IntegerTypedArray type and use it for crypto.getRandomValues
Sep 19, 2026
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.
crypto.getRandomValuesaccepted anyArrayBufferView(including float arrays, which browsers reject withTypeMismatchError), and its constraint-instantiated parameter type carried no typed-array members. Expressing the correct constraint requires a lib-level type, sinceBigInt64Array/BigUint64Arrayonly exist under ES2020.Analysis
The DOM signature was
getRandomValues<T extends Exclude<BufferSource, ArrayBuffer>>(array: T): T. Two consequences:crypto.getRandomValues(new Float64Array(1))type-checks, but throws at runtime.Parameters<typeof crypto.getRandomValues>[0]resolves toArrayBufferView, socrypto.getRandomValues(array).BYTES_PER_ELEMENTerrors with TS2339.Per WebCrypto §10.1.1, only the nine integer typed arrays are valid. Since the bigint views are gated on lib selection, the union has to be assembled via interface merging in the language libs rather than in TypeScript-DOM-lib-generator.
Fix
lib.es5.d.ts: addsIntegerTypedArrayTypesandtype IntegerTypedArray = IntegerTypedArrayTypes[keyof IntegerTypedArrayTypes], following the existingWeakKey/WeakKeyTypespattern. Members are declared overArrayBufferLike(rather than relying on theArrayBufferdefault) soSharedArrayBuffer-backed views andUint8Array<ArrayBufferLike>values such as Node'sBufferkeep working.lib.es2020.bigint.d.ts: mergesBigInt64Array/BigUint64ArrayintoIntegerTypedArrayTypes, so they only join the union when the ES2020 bigint lib is in play.lib.dom.d.ts/lib.webworker.d.ts: constraint changed togetRandomValues<T extends IntegerTypedArray>(array: T): T. These files are generated; the corresponding generator change belongs upstream in TypeScript-DOM-lib-generator.tsc/internal/fourslash/tests/util/util.go: adds the two new globals to the shared expected global-completion list.tsc/testdata/tests/cases/compiler/integerTypedArray.ts+ baselines cover acceptance, rejection, and theParameters<...>round trip.Copilot Checklist
I successfully ran the applicable command at the end of my session, and it completed without error:
IntegerTypedArraytype required for use withcrypto.getRandomValues#61768