Skip to content

Type error with ChromaticAberration #298

@Johnjackbogart

Description

@Johnjackbogart

Hi,

I have the below code:

import { useRef } from "react";
import * as THREE from "three";
import { useFrame } from "@react-three/fiber";
import {
  Bloom,
  EffectComposer,
  N8AO,
  TiltShift2,
  ChromaticAberration,
} from "@react-three/postprocessing";
import { ChromaticAberrationEffect, BlendFunction } from "postprocessing";
import { easing } from "maath";

export default function Effects() {
  const chromaRef = useRef<ChromaticAberrationEffect>(null);

  useFrame((state, delta) => {
    easing.damp3(
      state.camera.position,
      [
        Math.sin(-state.pointer.x) * 5,
        state.pointer.y * 2,
        0.5 + Math.cos(state.pointer.x) * 5,
      ],
      0.1,
      delta,
    );
    state.camera.lookAt(0, 0, 0);

    if (!chromaRef.current) return;
    const x = Math.sin(-state.pointer.x) / 100;
    const y = state.pointer.y / 100;
    const newOffset = new THREE.Vector2(x, y);
    chromaRef.current.offset = newOffset;
  });
  return (
    <EffectComposer enableNormalPass={true}>
      <ChromaticAberration
        ref={chromaRef}
        blendFunction={BlendFunction.NORMAL}
        offset={new THREE.Vector2(0.01, 0.01)}
        radialModulation={false}
        modulationOffset={1.0}
      />
      <Bloom mipmapBlur luminanceThreshold={0.8} intensity={2} levels={8} />
      <TiltShift2 blur={0.2} />
    </EffectComposer>
  );
}

I'm trying to animate the chromatic aberration offset.

However, I get the following error:

Type 'RefObject<ChromaticAberrationEffect>' is not assignable to type 'RefObject<typeof ChromaticAberrationEffect>'.
     Property 'prototype' is missing in type 'ChromaticAberrationEffect' but required in type 'typeof ChromaticAberrationEffect'.

I believe this is because the type is exported as typeof ChromaticAberrationEffect in react-three/postprocessing

instead of just ChromaticAberrationEffect

When I changed this in my node modules folder the issue is resolved

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions