-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v9] fix(useLoader): properly infer Loader types #2723
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b22c406:
|
I fixed this locally by extending all |
So this would be |
Also, |
The latter 2 are not supposed to be public, that was an oversight from #2598. Can use |
It ends up looking this, including for export interface Loader<T> 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<T>
}
export function useLoader<
T,
U extends string | string[] | string[][],
L extends LoaderProto<T>,
R = LoaderReturnType<T, L>,
>
...
useLoader.preload = function <T, U extends string | string[] | string[][], L extends LoaderProto<T>>
...
useLoader.clear = function <T, U extends string | string[] | string[][], L extends LoaderProto<T>> It's not pretty but it works. |
How is this looking? Last I tested it worked as intended. |
Hello, I'm having difficulty understanding the role of the third and fourth parameters in the type declaration for useLoader. Do users need to provide these parameters? Is it mandatory for users to specify them? And could you provide an example? |
They are not required to be specified in user-land, and I wish there was a way to hide them. They are populated implicitly through inference. |
Thank you for your response, but I'm currently facing the issue shown in the image below. I'm confused about how to address it because the third and fourth items are mandatory in the type declaration. The error message is 'Expected 3-4 type arguments, but got 2.ts(2558)' . And I reviewed the documentation again, and it turns out the last two items are not mandatory either. |
Is this since TypeScript 5? Sounds like a bug, will have to fix for latest versions. |
My ts version is "^5.0.2". Do I need to open a separate issue for this? |
This may need to be backported to master (#2341), but addresses a
useLoader
regression described in #2668 (comment).