Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Property 'object3D' does not exist on type 'Element'" error when trying to access Element.object3D in A-frame with TypeScript

First, I’m Japanese student. So, please forgive my poor English.
I’m developing a-frame library that make animation with anime.js in TypeScript now.
When I tried to accessing Element.object3D to update value of position, TypeScript generated "Property ‘object3D’ does not exist on type ‘Element’" error.
Here is my code.

function updateValue(target: Element, attr: Attribute, value: number) {
switch (attr) {
    case "PositionX":
        target.object3D.position.setX(value)
    case "PositionY":
        target.object3D.position.setY(value)
    case "PositionZ":
        target.object3D.position.setZ(value)

}

I realize ‘object3D’ does not exist on Element but when import a-frame it exists. I tried to require("aframe") but this problem was not fixed.
I apologize for the rudimentary nature of this question and my poor English, but I would be very grateful if you could answer it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You probably need to install @types/aframe package, to have the typings for your typescript project.

After that, use Entity or Scene (I don’t know which one is the one that you receive in updateValue but those 2 contain object3D.

function updateValue(target: Entity, attr: Attribute, value: number) {
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading