-
-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
See: https://devblogs.microsoft.com/typescript/announcing-typescript-5-9-rc/#notable-behavioral-changes
Notably, many standard APIs that expect a BufferSource
will fail at a type-level when supplied with a default Uint8Array
instead of Uint8Array<ArrayBuffer>
.
For example the following code does not compile anymore in Typescript 5.9.x:
function createBuffer1(): Uint8Array {
return new Uint8Array(1);
}
fetch('url', { body: createBuffer1() });
But the following one does:
function createBuffer2(): Uint8Array<ArrayBuffer> {
return new Uint8Array(1);
}
fetch('url', { body: createBuffer2() });
In particular the @noble/hashes library specifies the return types of the functions that return buffers as type Uint8Array
, which then requires the library consumers to explicitly type-cast to Uint8Array<ArrayBuffer>
, which is not best practice.
Would there be any chance to update the return types to Uint8Array<ArrayBuffer>
?
Metadata
Metadata
Assignees
Labels
No labels