【发布时间】:2018-01-24 08:05:05
【问题描述】:
这是一个演示:
class Vec2 {};
class Vec3 {};
class Vec4 {};
let mylibs = {
Vec2: Vec2,
Vec3: Vec3,
Vec4: Vec4
};
let len = Math.round(Math.random() * 2) + 2;
let VecType = 'Vec' + len;
let randomVector = new mylibs[VecType]();
我想通过用户输入创建一些东西,VecType 是我用来模拟用户输入的东西。
上面的代码有效,tsc 不会抛出任何错误。但是在我的 vscode 中,它告诉我一些错误。
我想解决这种错误。谢谢。
【问题讨论】:
标签: typescript