Missing type definition for BufferAttribute.setUsage?

I am using Typescript with THREE.

I recently upgraded THREE to r114, and realized that setDynamic(true | false) on BufferAttribute is now deprecated. I then switched to the newer syntax:

// before
geometry.attributes.position.setDynamic(true);

// after
geometry.attributes.position.setUsage(THREE.DynamicDrawUsage);

But my compiler started complaining:

Property 'setUsage' does not exist on type 'BufferAttribute | InterleavedBufferAttribute'.
Property 'setUsage' does not exist on type 'InterleavedBufferAttribute'.  TS2339

What are my options around this?

InterleavedBufferAttribute does not have the method and it seems TS does not know if your attribute is of type InterleavedBufferAttribute or BufferAttribute.

I’m not very familiar with TS but isn’t there an option to cast the type of a variable?

1 Like