PeculiarVentures/webcrypto

Crypto.randomUUID() definition breaks on TypeScript 5

gnarea opened this issue · 2 comments

node_modules/@peculiar/webcrypto/index.d.ts:4:10 - error TS2416: Property 'randomUUID' in type 'Crypto' is not assignable to the same property in base type 'Crypto'.
  Type '() => string' is not assignable to type '() => `${string}-${string}-${string}-${string}-${string}`'.
    Type 'string' is not assignable to type '`${string}-${string}-${string}-${string}-${string}`'.

4   public randomUUID(): string;
           ~~~~~~~~~~

Found 1 error in node_modules/@peculiar/webcrypto/index.d.ts:

And this is how the base Crypto interface is defined in TS 5:

interface Crypto {
    /** Available only in secure contexts. */
    readonly subtle: SubtleCrypto;
    getRandomValues<T extends ArrayBufferView | null>(array: T): T;
    /** Available only in secure contexts. */
    randomUUID(): `${string}-${string}-${string}-${string}-${string}`;
}

It all works after downgrading to TS 4.

The only fix I can think of would be using ${string}-${string}-${string}-${string}-${string} from now on, but that'd then break on TS 4, so it'd be a breaking change.

The latest version of webcrypto-core already uses TS v5 types
https://github.com/PeculiarVentures/webcrypto-core/blob/master/src/crypto.ts#L27

The latest version of @peculiar/webcrypto does it too

https://github.com/PeculiarVentures/webcrypto/blob/master/index.d.ts#L4

Cool, thanks!