While my TypeScript code compiles correctly, I have encountered a problem with my class structure that results in unexpected behavior and runtime errors.
The specific issue causing the error is
this.Scene = new THREE.Scene();
After running tsc, the line changes to
this.Scene = new three_1.default.Scene();
To resolve this, I can remove the default parameter, but doing so every time doesn't seem like the best approach. I'd like to understand the root cause of the issue. Below are the classes I am using for context if the structure might be related to the problem. Apologies in advance, as I am still learning TypeScript (and only started JavaScript a week ago, although I do have experience with .NET)
import { MaterialLibrary } from "./Materials/MaterialLibrary";
import { MeshLoader } from "./MeshLoader";
import THREE from "three";
export class Manager
{
//manager instance
private static instance: Manager;
//sub-managers
public static MaterialLib: MaterialLibrary;
public static Scene: THREE.Scene;
//helper classes
public static MeshLoader: MeshLoader;
constructor()
{
Manager.instance = this;
}
static Init()
{
this.MaterialLib = new MaterialLibrary();
this.MeshLoader = new MeshLoader();
this.Scene = new THREE.Scene();
}
static GetInstance(): Manager
{
if(!Manager.instance)
{
Manager.instance = new Manager();
}
return Manager.instance;
}
}
This code snippet compiles to
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const MaterialLibrary_1 = require("./Materials/MaterialLibrary");
const MeshLoader_1 = require("./MeshLoader");
const three_1 = __importDefault(require("three"));
class Manager {
constructor() {
Manager.instance = this;
}
static Init() {
this.MaterialLib = new MaterialLibrary_1.MaterialLibrary();
this.MeshLoader = new MeshLoader_1.MeshLoader();
this.Scene = new three_1.default.Scene();
}
static GetInstance() {
if (!Manager.instance) {
Manager.instance = new Manager();
}
return Manager.instance;
}
}
exports.Manager = Manager;