TypeScript代码正确编译。但是(可能)由于我的类结构而导致的编译结果与预期的不同。导致运行时错误。
导致错误本身的实际问题是
this.Scene = new THREE.Scene(); 运行TSC后,我得到这一行
this.Scene = new three_1.default.Scene(); 我可以删除默认参数并对其进行修复。但是,每次都这样做似乎是一个坏主意。我宁愿知道潜在的问题。上下文类,以防与我正在使用的结构相关。抱歉,我对打字稿比较陌生(一个星期前开始使用JS,但是我确实拥有.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;
}
} 并编译为
"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;
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。