javascript - 使用 TypeScript 和 Sails.js 出现问题,TypeError: 对象不是函数
我将我的 Sails.js 应用程序转换为使用 TypeScript,但当我尝试访问以前的路由时,会出现“TypeError: object is not a function”错误。
我使用一个类创建了一个控制器,并用 TypeScript 重写了我的函数。最后,我实例化了我的新控制器,操作如下
var controller = new TestController();
export = controller;
我不明白我在这里做错了什么。我参考了 http://alexclavelle.blogspot.com/2015/03/using-sailsjs-with-typescript.html?showComment=1435617822375 上的工作。
仍然没有动静...我猜可能是生成的 es5 代码出了问题。
答案#1
基于:
var controller = new TestController();
export = controller;
运行时无法执行 controller()。
修复:
var controller = () => new TestController();
export = controller;
