टाइपप्रति वी 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'
पर मौजूद नहीं हैमुझे क्या बदलना चाहिए?
धन्यवाद प्रतिक्रिया
मुझे लगता है: this.router.get ('/', ServerRouter.getIndex); ठीक होना चाहिए ... यदि हां? क्यूं कर ? (स्पष्टीकरण के लिए कोई लिंक) धन्यवाद – erwin