Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Argument of type 'Uint8Array' is not assignable to parameter of type 'number[]'

Based on crypto.subtle.exportKey("spki", cryptoKey) I want to convert the returned ArrayBuffer into a string so I can turn it into a base64 string. Based on the documentation I tried

const bufferAsString = String.fromCharCode.apply(null, new Uint8Array(buffer));

but TypeScript tells me

TS2345: Argument of type ‘Uint8Array’ is not assignable to parameter of type ‘number[]’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I fix the type errors?

>Solution :

Use parameters spread when you call the function instead of using apply (playground):

String.fromCharCode(...new Uint8Array(buf));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading