在将nodejs项目升级到打字稿时,如何替换``需要''函数?
我正在尝试将现有的Nodejs项目从JavaScript转换为打字稿,但我不知道如何处理需要
表达方式如下:
const indexRouter = require('../routes/index');
const config = require('./config');
编辑:这是index.ts.ts
迪尔:
import express, {Request, Response, NextFunction} from 'express';
const router = express.Router();
/* GET home page. */
router.get('/', function(req: Request, res: Response, next: NextFunction) {
res.render('index', { title: 'Express' });
});
export default router;
I am trying to modify an existing NodeJS project from JavaScript to TypeScript but I don't know how to deal with require
expressions like below:
const indexRouter = require('../routes/index');
const config = require('./config');
EDIT: This is the index.ts
dile:
import express, {Request, Response, NextFunction} from 'express';
const router = express.Router();
/* GET home page. */
router.get('/', function(req: Request, res: Response, next: NextFunction) {
res.render('index', { title: 'Express' });
});
export default router;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必更改这些行。 TypeScript通过依次配置了解Commonjs模块。但是,由于您想替换它们,我认为您想使用ES6模块。
它是
You don't have to change that lines. TypeScript understands CommonJS modules with the according configuration. But since you want to replace them, I assume you want to use ES6 modules.
It's