Skip to content

instanceof has been used and there is a type inference error #58793

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

Closed
moshuying opened this issue Jun 7, 2024 · 3 comments
Closed

instanceof has been used and there is a type inference error #58793

moshuying opened this issue Jun 7, 2024 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@moshuying
Copy link

πŸ”Ž Search Terms

Property 'dispose' does not exist on type 'string | number | boolean | Record<string, any> | Color | ((material: Material) => Material)

πŸ•— Version & Regression Information

image

⏯ Playground Link

No response

πŸ’» Code

export function disposeMaterial(material: THREE.Material) {
  if (material instanceof THREE.Material) {
    for (const key in material) {
      const k = key as keyof THREE.Material
      if (material[k] instanceof THREE.Texture) {
        //@ts-ignore 
        material[k].dispose()
      }
    }
    material.dispose()
  }
}

πŸ™ Actual behavior

no error

πŸ™‚ Expected behavior

no error

Additional information about the issue

No response

@moshuying
Copy link
Author

I can fix it, but I don't think it's right

export function disposeMaterial(material: THREE.Material) {
  if (material instanceof THREE.Material) {
    for (const key in material) {
      const k = key as keyof THREE.Material
      const e = material[k]
      if (e instanceof THREE.Texture) {
        // 销毁纹理
        e.dispose()
      }
    }
    // 销毁材质
    material.dispose()
  }
}

@Andarist
Copy link
Contributor

Andarist commented Jun 7, 2024

The upcoming 5.5 release fixes this: #57847

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 7, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants