From baf0b60d3efc0ee7bf940416212aca6d729d69ac Mon Sep 17 00:00:00 2001 From: Antoine BERNIER Date: Tue, 25 Jul 2023 00:57:37 +0200 Subject: [PATCH] chore: painfully trying to fix TS --- src/effects/ChromaticAberration.tsx | 2 +- src/effects/LensFlare.tsx | 2 +- src/util.tsx | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/effects/ChromaticAberration.tsx b/src/effects/ChromaticAberration.tsx index 0ef95949..ce0baf97 100644 --- a/src/effects/ChromaticAberration.tsx +++ b/src/effects/ChromaticAberration.tsx @@ -1,5 +1,5 @@ import { ChromaticAberrationEffect } from 'postprocessing' import { type EffectProps, wrapEffect } from '../util' -export type ChromaticAberrationProps = EffectProps +export type ChromaticAberrationProps = EffectProps export const ChromaticAberration = wrapEffect(ChromaticAberrationEffect) diff --git a/src/effects/LensFlare.tsx b/src/effects/LensFlare.tsx index 378b4fc2..3e6dd9e7 100644 --- a/src/effects/LensFlare.tsx +++ b/src/effects/LensFlare.tsx @@ -540,7 +540,7 @@ export const LensFlare = ({ const [projectedPosition] = useState(() => new THREE.Vector3()) const [mouse2d] = useState(() => new THREE.Vector2()) - const ref = useRef(null!) + const ref = useRef(null) useFrame((_, delta) => { if (!ref?.current) return diff --git a/src/util.tsx b/src/util.tsx index 198cd66a..8ea2b778 100644 --- a/src/util.tsx +++ b/src/util.tsx @@ -7,13 +7,14 @@ import type { Effect, BlendFunction } from 'postprocessing' export const resolveRef = (ref: T | React.MutableRefObject) => typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref -export type EffectConstructor = new (...args: any[]) => Effect +export type Constructor = new (...args: any[]) => T -export type EffectProps = ReactThreeFiber.Node< - T extends Function ? T['prototype'] : InstanceType, +export type EffectConstructor = Constructor +export type EffectProps = ReactThreeFiber.Node< + T extends Function ? T['prototype'] : InstanceType>, T > & - ConstructorParameters[0] & { + ConstructorParameters>[0] & { blendFunction?: BlendFunction opacity?: number } @@ -21,7 +22,7 @@ export type EffectProps = ReactThreeFiber.Node< let i = 0 const components = new WeakMap | string>() -export const wrapEffect = (effect: T, defaults?: EffectProps) => +export const wrapEffect = (effect: Constructor, defaults?: EffectProps) => /* @__PURE__ */ React.forwardRef>(function Effect( { blendFunction = defaults?.blendFunction, opacity = defaults?.opacity, ...props }, ref