From 1b602d4f6218a89b53cd078aec74cc291dd9df29 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Thu, 19 Jan 2023 17:47:31 -0600 Subject: [PATCH 01/10] fix(types): loosen Loader type --- packages/fiber/src/core/hooks.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index 10ab308bff..29717135bf 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -9,8 +9,8 @@ import type { Instance } from './reconciler' export interface Loader extends THREE.Loader { load( - url: string, - onLoad?: (result: T) => void, + url: string | string[], + onLoad?: (result: T, ...args: any[]) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, ): unknown From 7edff25f30b6c4aa4418ec0593bef7cbe68c13da Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 13:59:41 -0600 Subject: [PATCH 02/10] fix(types): accept string[][] in useLoader --- packages/fiber/src/core/hooks.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index 29717135bf..611b59e6ea 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -9,7 +9,7 @@ import type { Instance } from './reconciler' export interface Loader extends THREE.Loader { load( - url: string | string[], + url: string | string[] | string[][], onLoad?: (result: T, ...args: any[]) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, @@ -130,7 +130,12 @@ function loadingFn>( * Note: this hook's caller must be wrapped with `React.Suspense` * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader */ -export function useLoader, R = LoaderReturnType>( +export function useLoader< + T, + U extends string | string[] | string[][], + L extends LoaderProto, + R = LoaderReturnType, +>( Proto: L, input: U, extensions?: Extensions, @@ -148,7 +153,7 @@ export function useLoader>( +useLoader.preload = function >( Proto: L, input: U, extensions?: Extensions, @@ -160,7 +165,7 @@ useLoader.preload = function >(Proto: L, input: U) { +useLoader.clear = function >(Proto: L, input: U) { const keys = (Array.isArray(input) ? input : [input]) as string[] return clear([Proto, ...keys]) } From b255c2af34a3aaa7c46492db79117c00961ea5a9 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 15:08:26 -0600 Subject: [PATCH 03/10] fix(types): remove excess useLoader generics --- packages/fiber/src/core/hooks.tsx | 59 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index 2ea3d33bf9..a334540a93 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -2,7 +2,7 @@ import * as THREE from 'three' import * as React from 'react' import type { GLTF } from 'three/examples/jsm/loaders/GLTFLoader' import { suspend, preload, clear } from 'suspend-react' -import { context, RootState, RenderCallback, UpdateCallback, StageTypes } from './store' +import { context, RootState, RenderCallback, UpdateCallback, StageTypes, RootStore } from './store' import { buildGraph, ObjectMap, is, useMutableCallback, useIsomorphicLayoutEffect } from './utils' import { Stages } from './stages' import type { Instance } from './reconciler' @@ -13,8 +13,8 @@ export interface Loader extends THREE.Loader { onLoad?: (result: T, ...args: any[]) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, - ): unknown - loadAsync(url: string, onProgress?: (event: ProgressEvent) => void): Promise + ): T + loadAsync(url: string | string[] | string[][], onProgress?: (event: ProgressEvent) => void): Promise } export type LoaderProto = new (...args: any) => Loader @@ -42,7 +42,7 @@ export function useInstanceHandle(ref: React.MutableRefObject): React.Muta return instance } -export function useStore() { +export function useStore(): RootStore { const store = React.useContext(context) if (!store) throw new Error('R3F: Hooks can only be used within the Canvas component!') return store @@ -55,7 +55,7 @@ export function useStore() { export function useThree( selector: (state: RootState) => T = (state) => state as unknown as T, equalityFn?: (state: T, newState: T) => boolean, -) { +): T { return useStore()(selector, equalityFn) } @@ -78,7 +78,7 @@ export function useFrame(callback: RenderCallback, renderPriority: number = 0): * Executes a callback in a given update stage. * Uses the stage instance to indetify which stage to target in the lifecycle. */ -export function useUpdate(callback: UpdateCallback, stage: StageTypes = Stages.Update) { +export function useUpdate(callback: UpdateCallback, stage: StageTypes = Stages.Update): void { const store = useStore() const stages = store.getState().internal.stages // Memoize ref @@ -93,15 +93,17 @@ export function useUpdate(callback: UpdateCallback, stage: StageTypes = Stages.U * Returns a node graph of an object with named nodes & materials. * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph */ -export function useGraph(object: THREE.Object3D) { +export function useGraph(object: THREE.Object3D): ObjectMap { return React.useMemo(() => buildGraph(object), [object]) } -function loadingFn>( +const isGLTF = (data: unknown): data is GLTF => (data as any)?.scene instanceof THREE.Object3D + +function loadingFn>( extensions?: Extensions, onProgress?: (event: ProgressEvent) => void, ) { - return function (Proto: L, ...input: string[]) { + return function (Proto: L, ...input: string[]): Promise[]> { // Construct new loader and run extensions const loader = new Proto() if (extensions) extensions(loader) @@ -109,11 +111,11 @@ function loadingFn>( return Promise.all( input.map( (input) => - new Promise((res, reject) => + new Promise>((res, reject) => loader.load( input, - (data: any) => { - if (data.scene) Object.assign(data, buildGraph(data.scene)) + (data: LoaderReturnType) => { + if (isGLTF(data)) Object.assign(data, buildGraph(data.scene)) res(data) }, onProgress, @@ -131,42 +133,39 @@ function loadingFn>( * Note: this hook's caller must be wrapped with `React.Suspense` * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader */ -export function useLoader< - T, - U extends string | string[] | string[][], - L extends LoaderProto, - R = LoaderReturnType, ->( - Proto: L, +export function useLoader( + Proto: LoaderProto, input: U, - extensions?: Extensions, + extensions?: Extensions, onProgress?: (event: ProgressEvent) => void, -): U extends any[] ? BranchingReturn[] : BranchingReturn { +): U extends any[] + ? BranchingReturn, GLTF, GLTF & ObjectMap>[] + : BranchingReturn, GLTF, GLTF & ObjectMap> { // Use suspense to load async assets const keys = (Array.isArray(input) ? input : [input]) as string[] - const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], { equal: is.equ }) + const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], { equal: is.equ }) // Return the object/s return (Array.isArray(input) ? results : results[0]) as U extends any[] - ? BranchingReturn[] - : BranchingReturn + ? BranchingReturn, GLTF, GLTF & ObjectMap>[] + : BranchingReturn, GLTF, GLTF & ObjectMap> } /** * Preloads an asset into cache as a side-effect. */ -useLoader.preload = function >( - Proto: L, +useLoader.preload = function ( + Proto: LoaderProto, input: U, - extensions?: Extensions, -) { + extensions?: Extensions, +): void { const keys = (Array.isArray(input) ? input : [input]) as string[] - return preload(loadingFn(extensions), [Proto, ...keys]) + return preload(loadingFn(extensions), [Proto, ...keys]) } /** * Removes a loaded asset from cache. */ -useLoader.clear = function >(Proto: L, input: U) { +useLoader.clear = function (Proto: LoaderProto, input: U): void { const keys = (Array.isArray(input) ? input : [input]) as string[] return clear([Proto, ...keys]) } From f750f3acd4b15d2b494e91ca1d6160c2b4e0ee8d Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 15:23:00 -0600 Subject: [PATCH 04/10] chore(hooks): cleanup --- packages/fiber/src/core/hooks.tsx | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index a334540a93..4ee88bf2a5 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -18,14 +18,8 @@ export interface Loader extends THREE.Loader { } export type LoaderProto = new (...args: any) => Loader -export type LoaderReturnType> = T extends unknown - ? Awaited['loadAsync']>> - : T -// TODO: this isn't used anywhere, remove in v9 -export type LoaderResult = T extends any[] ? Loader : Loader export type Extensions }> = (loader: T['prototype']) => void -export type ConditionalType = Child extends Parent ? Truthy : Falsy -export type BranchingReturn = ConditionalType +export type BranchingReturn = T extends Parent ? Coerced : T /** * Exposes an object's {@link Instance}. @@ -103,7 +97,7 @@ function loadingFn>( extensions?: Extensions, onProgress?: (event: ProgressEvent) => void, ) { - return function (Proto: L, ...input: string[]): Promise[]> { + return function (Proto: L, ...input: string[]): Promise { // Construct new loader and run extensions const loader = new Proto() if (extensions) extensions(loader) @@ -111,10 +105,10 @@ function loadingFn>( return Promise.all( input.map( (input) => - new Promise>((res, reject) => + new Promise((res, reject) => loader.load( input, - (data: LoaderReturnType) => { + (data: T) => { if (isGLTF(data)) Object.assign(data, buildGraph(data.scene)) res(data) }, @@ -138,16 +132,14 @@ export function useLoader( input: U, extensions?: Extensions, onProgress?: (event: ProgressEvent) => void, -): U extends any[] - ? BranchingReturn, GLTF, GLTF & ObjectMap>[] - : BranchingReturn, GLTF, GLTF & ObjectMap> { +): U extends any[] ? BranchingReturn[] : BranchingReturn { // Use suspense to load async assets const keys = (Array.isArray(input) ? input : [input]) as string[] const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], { equal: is.equ }) // Return the object/s return (Array.isArray(input) ? results : results[0]) as U extends any[] - ? BranchingReturn, GLTF, GLTF & ObjectMap>[] - : BranchingReturn, GLTF, GLTF & ObjectMap> + ? BranchingReturn[] + : BranchingReturn } /** From 0340acd9059fc14655f57647ede2122a539abfe8 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 15:35:59 -0600 Subject: [PATCH 05/10] chore(types): more cleanup, update snapshot --- packages/fiber/src/core/hooks.tsx | 17 +++++++---------- .../tests/__snapshots__/index.test.tsx.snap | 3 --- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index 4ee88bf2a5..970bd5f052 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -17,8 +17,8 @@ export interface Loader extends THREE.Loader { loadAsync(url: string | string[] | string[][], onProgress?: (event: ProgressEvent) => void): Promise } -export type LoaderProto = new (...args: any) => Loader -export type Extensions }> = (loader: T['prototype']) => void +export type LoaderProto = new (...args: any[]) => Loader +export type Extensions = (loader: Loader) => void export type BranchingReturn = T extends Parent ? Coerced : T /** @@ -93,11 +93,8 @@ export function useGraph(object: THREE.Object3D): ObjectMap { const isGLTF = (data: unknown): data is GLTF => (data as any)?.scene instanceof THREE.Object3D -function loadingFn>( - extensions?: Extensions, - onProgress?: (event: ProgressEvent) => void, -) { - return function (Proto: L, ...input: string[]): Promise { +function loadingFn(extensions?: Extensions, onProgress?: (event: ProgressEvent) => void) { + return function (Proto: LoaderProto, ...input: string[]): Promise { // Construct new loader and run extensions const loader = new Proto() if (extensions) extensions(loader) @@ -130,8 +127,8 @@ function loadingFn>( export function useLoader( Proto: LoaderProto, input: U, - extensions?: Extensions, - onProgress?: (event: ProgressEvent) => void, + extensions?: Extensions, + onProgress?: (event: ProgressEvent) => void, ): U extends any[] ? BranchingReturn[] : BranchingReturn { // Use suspense to load async assets const keys = (Array.isArray(input) ? input : [input]) as string[] @@ -148,7 +145,7 @@ export function useLoader( useLoader.preload = function ( Proto: LoaderProto, input: U, - extensions?: Extensions, + extensions?: Extensions, ): void { const keys = (Array.isArray(input) ? input : [input]) as string[] return preload(loadingFn(extensions), [Proto, ...keys]) diff --git a/packages/fiber/tests/__snapshots__/index.test.tsx.snap b/packages/fiber/tests/__snapshots__/index.test.tsx.snap index ae8cad7a77..a2eb90ad01 100644 --- a/packages/fiber/tests/__snapshots__/index.test.tsx.snap +++ b/packages/fiber/tests/__snapshots__/index.test.tsx.snap @@ -14,7 +14,6 @@ Array [ "Catalogue", "Color", "ComputeFunction", - "ConditionalType", "ConstructorRepresentation", "Disposable", "DomEvent", @@ -41,8 +40,6 @@ Array [ "LegacyAlways", "Loader", "LoaderProto", - "LoaderResult", - "LoaderReturnType", "MathType", "ObjectMap", "Overwrite", From 0fc6afc366010633792bd13ecdd1c6369a22b968 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:10:30 -0600 Subject: [PATCH 06/10] refactor(hooks): try to infer useLoader type --- packages/fiber/src/core/hooks.tsx | 26 ++++++++----------- .../tests/__snapshots__/index.test.tsx.snap | 1 + 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index 970bd5f052..2932d63e68 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -1,6 +1,5 @@ import * as THREE from 'three' import * as React from 'react' -import type { GLTF } from 'three/examples/jsm/loaders/GLTFLoader' import { suspend, preload, clear } from 'suspend-react' import { context, RootState, RenderCallback, UpdateCallback, StageTypes, RootStore } from './store' import { buildGraph, ObjectMap, is, useMutableCallback, useIsomorphicLayoutEffect } from './utils' @@ -13,11 +12,12 @@ export interface Loader extends THREE.Loader { onLoad?: (result: T, ...args: any[]) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, - ): T + ): unknown loadAsync(url: string | string[] | string[][], onProgress?: (event: ProgressEvent) => void): Promise } export type LoaderProto = new (...args: any[]) => Loader +export type LoaderResult = T extends { scene: THREE.Object3D } ? T & ObjectMap : T export type Extensions = (loader: Loader) => void export type BranchingReturn = T extends Parent ? Coerced : T @@ -91,10 +91,8 @@ export function useGraph(object: THREE.Object3D): ObjectMap { return React.useMemo(() => buildGraph(object), [object]) } -const isGLTF = (data: unknown): data is GLTF => (data as any)?.scene instanceof THREE.Object3D - function loadingFn(extensions?: Extensions, onProgress?: (event: ProgressEvent) => void) { - return function (Proto: LoaderProto, ...input: string[]): Promise { + return function (Proto: LoaderProto, ...input: string[]) { // Construct new loader and run extensions const loader = new Proto() if (extensions) extensions(loader) @@ -102,13 +100,11 @@ function loadingFn(extensions?: Extensions, onProgress?: (event: ProgressE return Promise.all( input.map( (input) => - new Promise((res, reject) => + new Promise>((res, reject) => loader.load( input, - (data: T) => { - if (isGLTF(data)) Object.assign(data, buildGraph(data.scene)) - res(data) - }, + (data: any) => + res(data?.scene instanceof THREE.Object3D ? Object.assign(data, buildGraph(data.scene)) : data), onProgress, (error) => reject(new Error(`Could not load ${input}: ${error.message})`)), ), @@ -129,14 +125,14 @@ export function useLoader( input: U, extensions?: Extensions, onProgress?: (event: ProgressEvent) => void, -): U extends any[] ? BranchingReturn[] : BranchingReturn { +) { // Use suspense to load async assets const keys = (Array.isArray(input) ? input : [input]) as string[] const results = suspend(loadingFn(extensions, onProgress), [Proto, ...keys], { equal: is.equ }) - // Return the object/s - return (Array.isArray(input) ? results : results[0]) as U extends any[] - ? BranchingReturn[] - : BranchingReturn + // Return the object(s) + return (Array.isArray(input) ? results : results[0]) as unknown as U extends any[] + ? LoaderResult[] + : LoaderResult } /** diff --git a/packages/fiber/tests/__snapshots__/index.test.tsx.snap b/packages/fiber/tests/__snapshots__/index.test.tsx.snap index a2eb90ad01..254eaf00ad 100644 --- a/packages/fiber/tests/__snapshots__/index.test.tsx.snap +++ b/packages/fiber/tests/__snapshots__/index.test.tsx.snap @@ -40,6 +40,7 @@ Array [ "LegacyAlways", "Loader", "LoaderProto", + "LoaderResult", "MathType", "ObjectMap", "Overwrite", From 9c5d23a2853e4b1b3c98f3db79da8bff935634fb Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:25:30 -0600 Subject: [PATCH 07/10] chore(hooks): prune unused types --- packages/fiber/src/core/hooks.tsx | 29 +++++++++---------- .../tests/__snapshots__/index.test.tsx.snap | 1 - 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index 2932d63e68..e1f2868976 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -6,21 +6,6 @@ import { buildGraph, ObjectMap, is, useMutableCallback, useIsomorphicLayoutEffec import { Stages } from './stages' import type { Instance } from './reconciler' -export interface Loader extends THREE.Loader { - load( - url: string | string[] | string[][], - onLoad?: (result: T, ...args: any[]) => void, - onProgress?: (event: ProgressEvent) => void, - onError?: (event: ErrorEvent) => void, - ): unknown - loadAsync(url: string | string[] | string[][], onProgress?: (event: ProgressEvent) => void): Promise -} - -export type LoaderProto = new (...args: any[]) => Loader -export type LoaderResult = T extends { scene: THREE.Object3D } ? T & ObjectMap : T -export type Extensions = (loader: Loader) => void -export type BranchingReturn = T extends Parent ? Coerced : T - /** * Exposes an object's {@link Instance}. * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle @@ -91,6 +76,20 @@ export function useGraph(object: THREE.Object3D): ObjectMap { return React.useMemo(() => buildGraph(object), [object]) } +export interface Loader extends THREE.Loader { + load( + url: string | string[] | string[][], + onLoad?: (result: T, ...args: any[]) => void, + onProgress?: (event: ProgressEvent) => void, + onError?: (event: ErrorEvent) => void, + ): unknown + loadAsync(url: string | string[] | string[][], onProgress?: (event: ProgressEvent) => void): Promise +} + +export type LoaderProto = new (...args: any[]) => Loader +export type LoaderResult = T extends { scene: THREE.Object3D } ? T & ObjectMap : T +export type Extensions = (loader: Loader) => void + function loadingFn(extensions?: Extensions, onProgress?: (event: ProgressEvent) => void) { return function (Proto: LoaderProto, ...input: string[]) { // Construct new loader and run extensions diff --git a/packages/fiber/tests/__snapshots__/index.test.tsx.snap b/packages/fiber/tests/__snapshots__/index.test.tsx.snap index 254eaf00ad..a175c102c8 100644 --- a/packages/fiber/tests/__snapshots__/index.test.tsx.snap +++ b/packages/fiber/tests/__snapshots__/index.test.tsx.snap @@ -6,7 +6,6 @@ Array [ "Args", "AttachFnType", "AttachType", - "BranchingReturn", "Camera", "CameraProps", "Canvas", From 0d53ce90d845cb53bdf5497a4691e529362183e0 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 17:11:45 -0600 Subject: [PATCH 08/10] fix(hooks): Loader#load signature returns any --- packages/fiber/src/core/hooks.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index e1f2868976..e4dcd69970 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -82,7 +82,7 @@ export interface Loader extends THREE.Loader { onLoad?: (result: T, ...args: any[]) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, - ): unknown + ): any loadAsync(url: string | string[] | string[][], onProgress?: (event: ProgressEvent) => void): Promise } From 2847837dea4d3f09cfbedb9159aed3848e425ee2 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 17:12:55 -0600 Subject: [PATCH 09/10] fix(hooks): remove Loader#loadAsync https://github.com/pmndrs/react-three-fiber/pull/2742 --- packages/fiber/src/core/hooks.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index e4dcd69970..fb413178d5 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -83,7 +83,6 @@ export interface Loader extends THREE.Loader { onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, ): any - loadAsync(url: string | string[] | string[][], onProgress?: (event: ProgressEvent) => void): Promise } export type LoaderProto = new (...args: any[]) => Loader From b22c406292e0101b02020fa7b48048d03020c123 Mon Sep 17 00:00:00 2001 From: Cody Bennett <23324155+CodyJasonBennett@users.noreply.github.com> Date: Mon, 27 Feb 2023 17:19:02 -0600 Subject: [PATCH 10/10] fix: harden hooks tests --- packages/fiber/src/core/hooks.tsx | 2 +- packages/fiber/tests/hooks.test.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/fiber/src/core/hooks.tsx b/packages/fiber/src/core/hooks.tsx index fb413178d5..be2f1f7e41 100644 --- a/packages/fiber/src/core/hooks.tsx +++ b/packages/fiber/src/core/hooks.tsx @@ -82,7 +82,7 @@ export interface Loader extends THREE.Loader { onLoad?: (result: T, ...args: any[]) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void, - ): any + ): unknown } export type LoaderProto = new (...args: any[]) => Loader diff --git a/packages/fiber/tests/hooks.test.tsx b/packages/fiber/tests/hooks.test.tsx index b97a397256..844020f311 100644 --- a/packages/fiber/tests/hooks.test.tsx +++ b/packages/fiber/tests/hooks.test.tsx @@ -149,12 +149,14 @@ describe('hooks', () => { it('can handle useLoader with a loader extension', async () => { class Loader extends THREE.Loader { - load = (_url: string) => null + load(_url: string, onLoad: (result: null) => void): void { + onLoad(null) + } } let proto!: Loader - function Test() { + function Test(): null { return useLoader(Loader, '', (loader) => (proto = loader)) } await act(async () => root.render())