Replies: 14 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 |
Beta Was this translation helpful? Give feedback.
-
I don't think it's necessary to publish 2 However, I'm not totally sure how this impacts TypeScript versions below 5.7. |
Beta Was this translation helpful? Give feedback.
-
I accepted the PR, we'll see if it's a problem :p |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, I've reverted the commit because Angular 18 is depending on a older version of TypeScript, see #563. |
Beta Was this translation helpful? Give feedback.
-
I'll try to spend some time this week to figure this out. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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); |
Beta Was this translation helpful? Give feedback.
-
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); |
Beta Was this translation helpful? Give feedback.
-
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); |
Beta Was this translation helpful? Give feedback.
-
Why did you use |
Beta Was this translation helpful? Give feedback.
-
First of I don't consider this an actual bug, the library still works great for me, thanks! The issue appears when using Edit: |
Beta Was this translation helpful? Give feedback.
-
I seem to have made a fundamental error in using Edit: I'm remembering now why I used and UInt16Array. This was done on purpose in order to verify if TS would use it or not. However, if I remember corectlu, this testing approach was incorrect but I do not remember why. Anyway, I agree that adding a |
Beta Was this translation helpful? Give feedback.
-
@Scarabol The method to extract data as |
Beta Was this translation helpful? Give feedback.
-
I'm also moving the issue in the discussion tab since it's not a bug a zip.js. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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?
Beta Was this translation helpful? Give feedback.
All reactions