Skip to content

Incorrect type declaration for Crypto.getRandomValues #1194

Open
@microshine

Description

@microshine

Bug Report

🔎 Search Terms

WebCrypto, Crypto, getRandomValues

🕗 Version & Regression Information

  • This changed in 4.4

Description

Here is W3C spec for Crypto interface.

[Exposed=(Window,Worker)]
interface Crypto {
  [SecureContext] readonly attribute SubtleCrypto subtle;
  ArrayBufferView getRandomValues(ArrayBufferView array);
};

array argument in getRandomValues is ArrayBufferView but TS uses wrong interface declaration

interface Crypto {
    readonly subtle: SubtleCrypto;
    getRandomValues<T extends ArrayBufferView | null>(array: T): T;
}

Here is Google Chrome exception on getRandomValues usage with an empty argument
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions