Skip to content

Commit

Permalink
chore: painfully trying to fix TS
Browse files Browse the repository at this point in the history
  • Loading branch information
abernier committed Jul 24, 2023
1 parent c9788b3 commit 319a60e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/effects/ChromaticAberration.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChromaticAberrationEffect } from 'postprocessing'
import { type EffectProps, wrapEffect } from '../util'

export type ChromaticAberrationProps = EffectProps<typeof ChromaticAberrationEffect>
export type ChromaticAberrationProps = EffectProps<ChromaticAberrationEffect>
export const ChromaticAberration = wrapEffect(ChromaticAberrationEffect)
2 changes: 1 addition & 1 deletion src/effects/LensFlare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export const LensFlare = ({
const [projectedPosition] = useState(() => new THREE.Vector3())
const [mouse2d] = useState(() => new THREE.Vector2())

const ref = useRef<LensFlareEffect>(null!)
const ref = useRef<LensFlareEffect>(null)

useFrame((_, delta) => {
if (!ref?.current) return
Expand Down
12 changes: 6 additions & 6 deletions src/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import type { Effect, BlendFunction } from 'postprocessing'
export const resolveRef = <T,>(ref: T | React.MutableRefObject<T>) =>
typeof ref === 'object' && ref != null && 'current' in ref ? ref.current : ref

export type EffectConstructor = new (...args: any[]) => Effect
type Constructor<T = {}> = new (...args: any[]) => T

export type EffectProps<T extends EffectConstructor> = ReactThreeFiber.Node<
T extends Function ? T['prototype'] : InstanceType<T>,
export type EffectProps<T extends Effect> = ReactThreeFiber.Node<
T extends Function ? T['prototype'] : InstanceType<Constructor<T>>,
T
> &
ConstructorParameters<T>[0] & {
ConstructorParameters<Constructor<T>>[0] & {
blendFunction?: BlendFunction
opacity?: number
}

let i = 0
const components = new WeakMap<EffectConstructor, React.ExoticComponent<any> | string>()
const components = new WeakMap<Constructor, string>()

export const wrapEffect = <T extends EffectConstructor>(effect: T, defaults?: EffectProps<T>) =>
export const wrapEffect = <T extends Effect>(effect: Constructor<T>, defaults?: EffectProps<T>) =>
/* @__PURE__ */ React.forwardRef<T, EffectProps<T>>(function Effect(
{ blendFunction = defaults?.blendFunction, opacity = defaults?.opacity, ...props },
ref
Expand Down

0 comments on commit 319a60e

Please sign in to comment.