【问题标题】:using TypeScript and Sails.js is giving issues, TypeError: object is not a function使用 TypeScript 和 Sails.js 会出现问题,TypeError: object is not a function
【发布时间】:2015-06-29 23:13:22
【问题描述】:

将我的 Sails.js 应用程序转换为使用 TypeScript,当我尝试访问之前的路线时,我遇到了有关“TypeError:对象不是函数”的错误。

我使用类创建了一个控制器,并在 TypeScript 中重新编写了我的函数。最后我实例化了我的新控制器

var controller = new TestController();
export = controller;

我不明白我在这里做错了什么。我参考了在http://alexclavelle.blogspot.com/2015/03/using-sailsjs-with-typescript.html?showComment=1435617822375上完成的工作

还是什么都没有……我猜这是生成的 es5 代码。

【问题讨论】:

    标签: javascript node.js typescript sails.js


    【解决方案1】:

    基于:

    var controller = new TestController();
    export = controller;
    

    运行时不能做controller()

    修复:

    var controller = () => new TestController();
    export = controller;
    

    【讨论】:

    • 我认为这让我走得更远......虽然现在我的路线都搞砸了。我所有的路由都在控制台中给出了这个错误sails.js/node.js 启动错误:忽略了将路由(/)绑定到未知控制器的尝试::index.findthis
    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 2019-04-05
    • 2019-01-30
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 2018-12-24
    相关资源
    最近更新 更多