What do you use TypedArrays for in JavaScript/TypeScript?
lobste.rs·15h·
Discuss: Lobsters
📘Typescript
Preview
Report Post

I’ve recently been using TypedArrays more for manual memory management / custom data storage, and find myself somewhat struggling with the lack of good typing support in TypeScript w.r.t. TypedArrays. eg. Even if I can define a number value type union such as

type Kind = 0 | 1 | 2 | 3 | 4 | 5;

I have no way of defining a Uint8Array that contains only this Kind type. After working around this with arr[i] as Kind casting and getting bit a few times by refactorings breaking the code but the as cast types not catching this, I opened up a feature suggestion for TypeScript (the pits, I know...) to support this. One response I got was to say that this is a niche use-case, and that made me wonder:

What are JavaScript/TypeScript developers actually using TypedArrays…

Similar Posts

Loading similar posts...