Skip to content
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

TS2339: Property 'array' does not exist on type 'BufferAttribute | InterleavedBufferAttribute | GLBufferAttribute'. #389

Closed
Sean-Bradley opened this issue Mar 30, 2023 · 6 comments · Fixed by #432
Labels
bug Something isn't working

Comments

@Sean-Bradley
Copy link

Sean-Bradley commented Mar 30, 2023

Since @types/[email protected] and @types/[email protected]

Sample code,

const numbers = somemesh.geometry.attributes.position.array

now causes error

TS2339: Property 'array' does not exist on type 'BufferAttribute | InterleavedBufferAttribute | GLBufferAttribute'.
  Property 'array' does not exist on type 'GLBufferAttribute'.

Two temporary fixes,
npm install @types/[email protected]
or
const numbers = (somemesh.geometry.attributes.position as any).array

In plain JavaScript ([email protected]), you can still reference a geometries attributes.position.array without issue.

At the time of writing this issue, @types/[email protected] did not yet exist.

@Sean-Bradley Sean-Bradley added the bug Something isn't working label Mar 30, 2023
@Methuselah96
Copy link
Contributor

An attribute can be a GLBufferAttribute which does not have an array property (see #314). For now you can either cast it if you know it's not a GLBufferAttribute or "use the boolean flags (isBufferAttribute, isInterleavedBufferAttribute, or isGLBufferAttribute) to discriminate between the different options."

@Methuselah96
Copy link
Contributor

Methuselah96 commented Mar 30, 2023

Something like #241 could be a potential solution to resolving this friction.

@Sean-Bradley
Copy link
Author

Sean-Bradley commented Mar 30, 2023

Ok, so it works if you do something like this

// using @types/[email protected]
const line = new THREE.Line( geometry, material );
const positions = (line.geometry.attributes.position as THREE.BufferAttribute).array

There was much less friction when the type was auto inferred and you could just write

// using @types/[email protected]
const line = new THREE.Line( geometry, material );
const positions = line.geometry.attributes.position.array

Is it really necessary to now also enforce the GLBufferAttribute type?
along with THREE.BufferAttribute | THREE.InterleavedBufferAttribute
Are you sure?

@Methuselah96
Copy link
Contributor

Methuselah96 commented Mar 30, 2023

Yes, that is generally how I've worked around the issue so far.

I agree that the friction is undesirable since the vast majority of three.js code does not use GLBufferAttributes, however on the other end, the types need to be able to support GLBufferAttributes since they're a valid buffer attribute.

I'm looking into ways to reduce the friction as much as possible while still retaining support for GLBufferAttributes.

@Methuselah96
Copy link
Contributor

Is it really necessary to now also enforce the GLBufferAttribute type?
along with THREE.BufferAttribute | THREE.InterleavedBufferAttribute
Are you sure?

Yes, we need to allow the use of GLBufferAttribute, since it's part of three.js. How to allow its use while preserving the ease of using BufferAttribute | InterleavedBufferAttribute takes a little more work, which I am exploring at the moment.

@Methuselah96
Copy link
Contributor

Reopening this to track this issue. I started working on this last month but hit some issues. Digging back into it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants