Wrong type in the sceneLoader

Try to make it in typescript:

TS2339: Property 'loggingEnabled' does not exist on type 'ISceneLoaderPlugin | ISceneLoaderPluginAsync'.
  Property 'loggingEnabled' does not exist on type 'ISceneLoaderPlugin'.

Current decision is:

(loader as any).loggingEnabled = true;

It works in runtime.

This is not really a bug in the documentation, as the code snippets are in javascript.

You can also do (loader as BABYLON.GLTFFileLoader).loggingEnabled = true; to better show that the property belongs to the glTF file loader.

2 Likes

Sorry, I mean this is a bug of TypeScript, not documentation. As I know, usage type casting is a bad practice.
It might be solved like:

interface ISceneLoaderPluginDefault {
  name: string;
  // ...
}

interface ISceneLoaderPluginGLTFFileLoader extends ISceneLoaderPluginDefault {
  name: 'gltf';
  loggingEnabled: boolean;
  // ...
}

export type ISceneLoaderPlugin = ISceneLoaderPluginDefault | ISceneLoaderPluginGLTFFileLoader;

Code like this will not require as for type casting in the developers code, because TypeScript after condition if (loader.name === 'gltf') will now that is a ISceneLoaderPluginGLTFFileLoader and it contains loggingEnabled field.

2 Likes

Sounds like the best way to do it !!!