Skip to content
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

useGLTF dry-types #2116

Merged
merged 3 commits into from
Oct 7, 2024
Merged

useGLTF dry-types #2116

merged 3 commits into from
Oct 7, 2024

Conversation

abernier
Copy link
Member

@abernier abernier commented Oct 5, 2024

Why

What

Checklist

  • Ready to be merged

Copy link

vercel bot commented Oct 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
drei ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 7, 2024 6:22am

Copy link

codesandbox-ci bot commented Oct 5, 2024

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.

Comment on lines +9 to +12
type Path = string | string[]
type UseDraco = boolean | string
type UseMeshopt = boolean
type ExtendLoader = (loader: GLTFLoader) => void
Copy link
Member Author

@abernier abernier Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's all about reusing those 4 types

useDraco: boolean | string = true,
useMeshOpt: boolean = true,
extendLoader?: (loader: GLTFLoader) => void
): T extends any[] ? (GLTF & ObjectMap)[] : GLTF & ObjectMap {
Copy link
Member Author

@abernier abernier Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: T extends any[] ? (GLTF & ObjectMap)[] : GLTF & ObjectMap

@CodyJasonBennett we should "normally" be able to remove this return type value, since it should be inferred by useLoader but I have teste and & ObjectMap is missing if we do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is still the case with latest R3F v8. R3F v9 should do this correctly, so we'll at least be able to remove this in the next major. Not eager to remove anything now with how volatile the types are when inferred.

type ExtendLoader = (loader: GLTFLoader) => void

function extensions(useDraco: UseDraco = true, useMeshopt: UseMeshopt = true, extendLoader?: ExtendLoader) {
return (loader: GLTFLoader) => {
Copy link
Member Author

@abernier abernier Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: GLTFLoader type-assertion instead of : Loader => it avoids multiple as GLTFLoader later in the function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants