I ran npm update on an older TypeScript project today. When I subsequently tried to compile the project, I was getting an error on a piece of code that was previously working:
const arrayTextureTestA = (data: Uint8Array) => {
return new DataArrayTexture(data, 1024, 1024, 6)
}
ERROR in ./src/textures.ts:112:30
TS2345: Argument of type 'Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'BufferSource'.
Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'ArrayBufferView<ArrayBuffer>'.
Types of property 'buffer' are incompatible.
Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
Types of property '[Symbol.toStringTag]' are incompatible.
Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.
110 | }
111 | const arrayTextureTestA = (data: Uint8Array) => {
> 112 | return new DataArrayTexture(data, 1024, 1024, 6)
| ^^^^
113 | }
Why does DataArrayTexture not accept a Uint8Array anymore?
This makes the error go away:
const arrayTextureTestB = (data: Uint8Array) => {
return new DataArrayTexture(new Uint8Array(data), 1024, 1024, 6)
}
// or like this
const arrayTextureTestC = (data: Uint8Array) => {
return new DataArrayTexture(data as Uint8Array<ArrayBuffer>, 1024, 1024, 6)
}
This works, but I would like to understand the weirdness. Why is new Uint8Array(data) accepted but the plain data array is not?
I’m currently using three.js 0.180.0.