Property 'name' does not exist on type 'IPhysicsEnabledObject'

I’ve run into this issue in a few different areas when using Typescript. For some reason, Typescript says something doesn’t exist when it clearly does. This time it’s when trying to access the name of an object when using the “registerOnPhysicsCollide”.

Here is a playground (with Typescript) that I’ve created that has the same issue: Babylon.js Playground

Here it is with Javascript: Babylon.js Playground and it works just fine there, but I assume that’s because Javascript is looser with this. How can I access the name of the object in Typescript?

This is because the colllided.object is an IPhysicsEnabledObject:
Babylon.js/physicsImpostor.ts at 6a6d300be5bbd78bf44804d310b84dee4f228ed5 · BabylonJS/Babylon.js (github.com)

So from a TS standpoint the object cannot have (for sure) other properties. That being said, as a developer you can supersede that with this code:

console.log("collidedname ", (collided.object as BABYLON.Mesh).name);
1 Like

Thanks, that makes sense.