-
Notifications
You must be signed in to change notification settings - Fork 516
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
With TypeScript 5.7 getData returns ArrayBufferLike instead of ArrayBuffer #549
Comments
Thank for the info. Actually, I don't use TS for development and I was not aware of this issue. I wonder how to deal with that. I guess somehow I would need to publish 2 |
I accepted the PR, we'll see if it's a problem :p |
Unfortunately, I've reverted the commit because Angular 18 is depending on a older version of TypeScript, see #563. |
I'll try to spend some time this week to figure this out. |
Thanks! I wonder if waiting would be the easiest solution. It seems that this problem doesn't really bother developers who use TS 5.7+ today. |
Actually, I'm probably wrong. For the record, ChatGPT suggests these fixes:
I have some doubts regarding the first suggestion. The second one is interesting, I'll try to test it. EDIT: None of these suggestions actually work in https://www.typescriptlang.org/play/. However ChatGPT is now saying me that I shouldn't need to change anything in fact... EDIT 2: The solution below seems to work. type CompatibleUint8Array =
Uint8Array extends { new (...args: any[]): infer U }
? U
: Uint8Array; EDIT 3: type CompatibleUint8Array =
Uint8Array extends { new (...args: any[]): infer U }
? U
: Uint8Array;
function test(val: CompatibleUint8Array): void {
console.log(val);
}
const val:Uint8Array = new Uint8Array([1, 2, 3]);
test(val);
const val:Uint8Array<ArrayBufferLike> = new Uint8Array([1, 2, 3]);
test(val); |
This does not work actually. The code below should not trigger an error in TS 5.7+ but it does. type CompatibleUint8Array =
Uint8Array extends { new (...args: any[] ): infer U }
? U
: Uint16Array;
function test(val: CompatibleUint8Array): void {
console.log(val);
}
const val:Uint8Array = new Uint8Array([1, 2, 3]);
test(val); |
I'm wondering if it's really an issue. I mean that the code below runs fine in the TS playground with TS 5.7+. @Scarabol, any thoughts? function test(val: Uint8Array): void {
console.log(val);
}
const val:Uint8Array = new Uint8Array([1, 2, 3]);
test(val);
const val2:Uint8Array<ArrayBufferLike> = new Uint8Array([1, 2, 3]);
test(val2); |
Thank you all for this great library! I appreciate using it in my project. I just tried to update my TypeScript version from
5.6.3
to5.7.2
.Starting with Typescript 5.7 typed arrays become generic. See:
ArrayBufferLike
microsoft/TypeScript#59417This affects for example the type definition of Uint8ArrayWriter
Previously with TypeScript 5.6.3 the following code typed
data
asArrayBuffer
, but starting with TypeScript > 5.7data
has typeArrayBufferLike
.My tsconfig compiler target is and has been set to ES2021.
I'm not sure how this is solved properly. My guess would be to add generic type explicitly to all
TypedArrays
usages, since they use Uint8Array (Example) actually. Effectively changing type definition here into this:What do you think?
The text was updated successfully, but these errors were encountered: