I don’t have a playground reproduction because this problem occurs specifically in vscode/my editor.
The issue I’m having is that the BABYLON namespace seems to be imported/declared globally in typescript (or something? I’m new at typescript).
In particular, if I import any babylonjs
export in one file (e.g. import {Engine} from 'babylonjs'
), vscode seems to recognize the BABYLON
namespace in all other files, where I would expect it not to (i.e. throw an error about not knowing the BABYLON
namespace).
So for example, suppose I have a file like babylon.ts
containing the code
import {Engine} from 'babylonjs';
const canvas: HTMLCanvasElement = document.createElement('canvas');
document.body.appendChild(canvas);
// Note that this line doesn't work at all,
// and throws the error "Type 'import("babylonjs/Engines/engine").Engine' is not assignable to type 'BABYLON.Engine'."
engine = new Engine(canvas,true);
and another file, say babylon_objects.ts
, that contains just
// Would expect vscode to throw an error like "Cannot find name BABYLON"
const vector = BABYLON.Vector3.Zero();
What I would expect is that vscode would be upset about me trying to using the name/namespace BABYLON
in babylon_objects.ts
without having declared it anywhere, but instead it seems fine with it, lets me compile the code, and then I get an error like the following from the browser (noting that I have to change the line engine = new Engine(canvas,true);
to engine = new BABYLON.Engine(canvas,true);
to get the code to compile).
babylon.ts:20 Uncaught ReferenceError: BABYLON is not defined
at new D (babylon.ts:20:27)
at index.ts:4:25
at index.ts:10:24
Again, I don’t have a playground to demonstrate this, but I do have the repo with the code, if someone wants to try this for themselves.
Can someone help me understand what’s going on here?
Please let me know what other info that I have not provided would be useful. Thanks.