【问题标题】:TypeScript- NodeJS - Unexpected token; 'constructor, function, accessor or variable'TypeScript- NodeJS - 意外的令牌; '构造函数、函数、访问器或变量'
【发布时间】:2016-03-30 14:21:43
【问题描述】:

我在 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.

【问题讨论】:

    标签: javascript node.js typescript gulp


    【解决方案1】:

    您不能在类声明中调用方法。 this.testing() 行不能去那里。

    不清楚您为什么要在那里调用该方法,或者您认为何时会调用该方法。也许您正在寻找构造函数?就目前而言,这条线在那个位置没有意义。

    【讨论】:

    • 是的,关于学习报班的问题,谢谢。
    猜你喜欢
    • 2016-09-12
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多