Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto.randomUUID() definition breaks on TypeScript 5 #64

Closed
gnarea opened this issue Mar 22, 2023 · 2 comments
Closed

Crypto.randomUUID() definition breaks on TypeScript 5 #64

gnarea opened this issue Mar 22, 2023 · 2 comments

Comments

@gnarea
Copy link

gnarea commented Mar 22, 2023

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.

gnarea added a commit to relaycorp/webcrypto-kms-js that referenced this issue Mar 22, 2023
@microshine
Copy link
Collaborator

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

@gnarea
Copy link
Author

gnarea commented Apr 3, 2023

Cool, thanks!

@gnarea gnarea closed this as completed Apr 3, 2023
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

No branches or pull requests

2 participants