我在nodejs中有一个应用程序,使用VS Code,使用gulp-typescript-compiler,目标ECS5,commonjs进行编译。创建一个错误的基本类'错误:意外的令牌; 'src / app / Test.ts第7行上的'构造函数,函数,访问器或变量'。'
以下代码:
class Test {
public name:string;
testing () {
console.log('tested...');
}
this.testing();
}
//gulp task error compile
//Error: Unexpected token; 'constructor, function, accessor or variable' expected on src/app/Test.ts line 7.
答案 0 :(得分:3)
您无法在类声明中调用方法。 this.testing()
行不能去那里。
不清楚为什么要调用那里的方法,或者当你认为会调用该方法时。也许您正在寻找构造函数?就目前而言,那条线在那个位置毫无意义。