Hello, thanks for popping in to help.
Context:
I’ve just started using Babylon.JS with TypeScript. I’m reasonably comfortable with TypeScript syntax and expectations, but there’s a solid chance I’m missing something simple or obvious; I don’t have native common sense yet!
I have plenty of experience with type-safe languages however.
Problem:
I’ve been having trouble accessing inherited members, with TypeScript spitting out errors like:
(thing as Texture).readPixels();
// Property 'readPixels' does not exist on type 'Texture'. ts(2339)
(thing as BaseTexture).getSize();
// Property 'getSize' does not exist on type 'BaseTexture'. ts(2339)
Edit: This is Visual Studio Code’s TypeScript language support, my project does build and run as expected.
I’ve been researching other threads and found cases where (for example) a user is attempting to access material.albedoTexture
, where material is Material
and so the albedoTexture
property is not visible without a cast.
The type is boxed; this behavior is inline with my expectations of type-safe languages.
However in my case, these inherited members should be known to exist statically, and are “safe”.
Is it really expected that I perform casts to base classes when accessing inherited members?
Could I be missing something here?