Javascript 无法将TypeScript服务器端与node.js一起使用(仅限继承)
我不明白为什么TS中的继承如此棘手。它在我的“控制器”上不起作用。我试着用AMD和commonJS进行编译,结果是一样的 UserController 上一个代码调用:Javascript 无法将TypeScript服务器端与node.js一起使用(仅限继承),javascript,node.js,typescript,Javascript,Node.js,Typescript,我不明白为什么TS中的继承如此棘手。它在我的“控制器”上不起作用。我试着用AMD和commonJS进行编译,结果是一样的 UserController 上一个代码调用: module.exports = require('./ts/UserController.ts').UserController; 但是我得到了一个未定义的对象。如果我删除extends和call(),我就得到了对象。 我只是不明白,我试着修了3个小时,但没有得到任何好的结果 有一些关于在nodejs服务器端使用TS的教程。
module.exports = require('./ts/UserController.ts').UserController;
但是我得到了一个未定义的对象。如果我删除extends和call(),我就得到了对象。
我只是不明白,我试着修了3个小时,但没有得到任何好的结果
有一些关于在nodejs服务器端使用TS的教程。。。
我在其他地方使用TS,它对服务器和客户端都有效,代码相同,但它是相同的,当我扩展时,我遇到了问题。您的
UserController
和Controller
代码是有效的,应该可以工作
错误似乎出现在
var obj=require('./../app/controllers/'+controllerName+“.js”)中。
您不应该需要js
扩展。在服务器端,看起来我们应该使用“//”添加引用,并导入和要求我们要继承的类/接口。我今天做了一些有用的事情。但我一点也不确定还有什么。。。令人惊讶的是……我记得我尝试过使用和不使用扩展,但我想没有任何更改,事实是我完全更改了这部分代码,并且在我的应用程序中使用sails.js来拥有强大的MVC模式。
///<reference path='../../../../shared/lib/public/def/defLoader.d.ts'/>
import express = require("express");
export class Controller{
public static beforeSharedPath: string = path.join(__dirname, "../../public");
public static publicPath: string = path.join(__dirname, '../../');
public static sharedPath: string = Controller.beforeSharedPath+"/shared";
public static webServerPath: string = path.join(__dirname, '../../');
public req: express.Request;
public res: express.Response;
public constructor(req: express.Request, res: express.Response){
this.req = req;
this.res = res;
}
public static __before(req: express.Request, res: express.Response, next: Function){
next();
}
public static __after(req: express.Request, res: express.Response, next: Function){
next();
}
}
var obj = require('./../app/controllers/' + controllerName+".js")
module.exports = require('./ts/UserController.ts').UserController;