Type of <mesh> and <canvas> with fiber and typescript?


I have problem typing that :

function EnsembleImage(): ? {
  return (
        <cylinderGeometry args={[0.03, 0.03, length, 16]} />
        <meshStandardMaterial color="white" />

It doesn’t work if I indicate Three.mesh.
What type should I indicate ? and what is the type of ? Thank you

In this case, i think you don’t need to indicate the return type.


function EnsembleImage() {

It should auto infer to JSX.Element

1 Like

just make sure you have @types/three installed, it must auto infer everything. your ide should have have types ready for auto complete and hover-over. function output must be inferred, input can be handled like so:

function Foo(props: JSX.IntrinsicElements['group'])
  const ref = useRef<THREE.Group>(null!)
  // ...
  return <group ref={ref} {...props} />

<Foo position={[1,2,3]} scale={2} rotation-x={Math.PI / 2}>
  <mesh />
  <group />
1 Like