【发布时间】:2017-08-20 11:50:17
【问题描述】:
打字稿 v 2.1.0
我写了如下ServerRouter.ts
import {Router, Request, Response, NextFunction} from 'express';
export class ServerRouter {
router: Router;
/**
* Initialize the ServerRouter
*/
constructor() {
this.router = Router();
this.init();
}
/**
* GET index page
*/
public getIndex(req: Request, res: Response, next: NextFunction) {
res.render('index');
}
/**
* Take each handler, and attach to one of the Express.Router's
* endpoints.
*/
init() {
this.router.get('/', this.getIndex);
}
}
// Create the ServerRouter, and export its configured Express.Router
const serverRouter = new ServerRouter().router;
export default serverRouter;
Webstorm 检查警告
> 方法可以是静态的
提出了关于 getIndex() 函数:
但是
如果我把它改成静态的
公共静态getIndex()
,我收到一个错误:TS2339 'getIndex' 在类型'ServerRouter' 上不存在
我应该改变什么?
感谢反馈
【问题讨论】:
标签: typescript static