The error message "Property X is not found on Object3D<Event>" occurred while using Three.js in conjunction with React-Three-Fiber

Currently, I'm utilizing React Three Fiber in combination with TypeScript to type my React Application. Here is a snippet of the code I am working on:

return (
    <group ref={group} dispose={null}>
      <scene name="Scene" {...props}>
        <mesh
          ref={mesh}
          scale={1.5}
          name="Object_0"
          morphTargetDictionary={nodes.Object_0.morphTargetDictionary}
          morphTargetInfluences={nodes.Object_0.morphTargetInfluences}
          rotation={[Math.PI / 2, 0, 0]}
          geometry={nodes.Object_0.geometry}
          material={materials.Material_0_COLOR_0}
        />
      </scene>
    </group>
  );

However, a persistent error keeps occurring:

Property: 'morphTargetDictionary' does not exist on type 'Object3D<Event>
, and a similar issue persists with morphTargetInfluences as well as geometry.

I attempted the following solution as I believe that these properties need to be included within the declaration of the Object3D (I am using the npm package @types/three), but unfortunately, it did not yield any positive results.

declare module '@types/three' {
  export default interface Object3D {
    morphTargetDictionary: number;
    morphTargetInfluences: number
    geometry: string
  }
}

Thank you in advance for your assistance!

Answer №1

After much searching, I finally discovered the solution - utilizing assertions in Typescript to specify the type of value being used:

return (
    <group ref={group} dispose={null}>
      <scene name="Scene" {...props}>
        <mesh
          ref={mesh}
          scale={1.5}
          name="Object_0"
          morphTargetDictionary={(nodes.Object_0 as THREE.Mesh).morphTargetDictionary}
          morphTargetInfluences={(nodes.Object_0 as THREE.Mesh).morphTargetInfluences}
          rotation={[Math.PI / 2, 0, 0]}
          geometry={(nodes.Object_0 as THREE.Mesh).geometry}
          material={materials.Material_0_COLOR_0}
        />
      </scene>
    </group>
  );

This is necessary because THREE.Mesh inherits from Object3D, which includes morphTargetDictionary as a class attribute.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There was no corresponding state found in the storage for OidcClient.readSigninResponseState using oidc-client in conjunction with React and Typescript

While browsing through related threads on the topic, I found that many of them are inactive or lack a definitive solution. In my project, I am working on a client using react and typescript. I have integrated the oidc-client module to interact with an ext ...

Ways to halt the execution of a setTimeout function within a loop

This question is a follow-up from this thread - setTimeout inside a loop, stops script from working I'm facing an issue with my script that fetches data from an API and stores it in a MongoDB collection. The problem seems to be related to the setTime ...

Using any random function as a property value in a TypeScript React Component

I am facing a challenge in my React component where I need to define a property that can accept any arbitrary function which returns a value, regardless of the number of arguments it takes. What matters most to me is the return value of the function. Here ...

TypeScript class featuring a unique method that is not utilized in every instance

I have a TypeScript class that is managing ZMQ bus communication. Initially, I created a general class that can be instantiated multiple times. However, now I need to create instances with slight variations that do not perfectly fit the generic class I o ...

Formik's conditional validation feature is not functioning properly

My form includes multiple inputs, one of which is a file input. The number of file inputs can vary: <EuiFilePicker id={`templateFiles.${index}.documentTemplate`} name={`templateFiles.${index}.documentTemplate`} display="default" ...

One way to update the value of the current array or object using ngModel in Angular 2 is to directly

I have a situation where I am dealing with both an array and an object. The array is populated with data retrieved from a service, while the object contains the first element of that array. feesEntries: Array<any> = []; selectedFeesEntry: any; clien ...

Ways to update a JavaScript variable without needing to refresh the entire webpage

I am working on a Three.JS application where objects are colored based on values from a text file: let color1 = 0x00ff00; let color2 = 0xFF04F0; Within the Three.JS code: var cubeGeometry = new THREE.BoxGeometry(15, 1, 5); var cubeMaterial = new THREE.M ...

Harness the power of TypeScript in a single test file with jest's expect.extend() method

This question is similar to Can you limit the scope of a TypeScript global type? but it presents a slightly different scenario that requires clarification (although an answer to this would be greatly appreciated as well). In my Jest setup, I am attempting ...

Mastering mapped types to replace properties in Typescript

I have created a Factory function where it takes an object as input and if that object contains specific properties, the factory transforms those properties into methods. How can I utilize mapped Types to accurately represent the type of the resulting obj ...

Declaration of TypeScript type

Could anyone provide an explanation of what this TypeScript declaration means? I understand that type and interface can be used to define new data types, but this particular statement is confusing to me. type ParameterizedContext<StateT = DefaultState, ...

SystemJS is loading classes that are extending others

In my Angular2 application, I have two classes where one extends the other. The first class is defined in the file course.ts (loaded as js) export class Course { id:string; } The second class is in schoolCourse.ts (also loaded as js) import {Cours ...

Importing modules that export other modules in Typescript

I am facing an issue with two modules and two classes. ModuleA, ModuleB, ClassA, and ClassB are defined as follows: export class ClassA { } export class ClassB { } The modules are structured like this: export * from './ClassA'; export module ...

Try incorporating "vector.applyQuaternion" or a similar method in your code within ammo.js

I'm eager to develop a virtual reality shooting game for browsers, utilizing Three.js and Ammo.js for the physics engine and rigid bodies. Although I've successfully set up the VR headset, controllers, and loaded models, I encountered an issue wi ...

It is impossible to add a promise's value to an array

When attempting to push values into an array and return them, the console only displays an empty array or shows undefined! The issue seems to be that .then does not properly pass the value to the array. const net = require('net'); const find = re ...

Strategies for avoiding unused style tags in React components

Expanding beyond React, I'm unsure if React itself is the culprit of this issue. In a React environment with TypeScript, I utilize CSS imports in component files to have specific stylesheets for each component. I assumed these styles would only be ad ...

Is there a way for me to generate a custom subtype of Error that can be thrown?

I am attempting to create my own custom error in order to handle it differently when catching it. I want to be able to call if(instanceof DatabaseError) and execute my specific handling logic. export class DatabaseError extends Error { constructor(...a ...

Allowing cross-origin resource sharing (CORS) in .NET Core Web API and Angular 6

Currently, I am facing an issue with my HTTP POST request from Angular 6. The request is successfully hitting the .net core Web API endpoint, but unfortunately, I am not receiving the expected response back in Angular 6. To make matters worse, when checkin ...

Type returned by a React component

I am currently using a basic context provider export function CustomStepsProvider ({ children, ...props }: React.PropsWithChildren<CustomStepsProps>) => { return <Steps.Provider value={props}> {typeof children === 'function&ap ...

I'm having trouble getting the drag event to work for Three.js trackball controls within a UIkit

The issue at hand involves a fullscreen Three.js canvas that is functioning perfectly, but there are limitations when displaying a preview in a UIkit modal – zooming works, but panning does not. JS: Renderer and Controls renderer = new THREE.WebGLRende ...

Utilizing various camera set-ups within Three.js

How can I smoothly switch between two different cameras in Three.js while transitioning from one to the other? Imagine a scene with a rock and a tree, each having its own dedicated camera setup. I'm looking for a way to seamlessly transition between ...