我正在运行 tsc --watch (将打字稿编译成javascript)并发出警告:
router/PostRouter.ts(103,16): error TS2503: Cannot find namespace 'postRoutes'.
在103字符串中的.ts文件中:
const postRoutes = new PostRouter();
postRoutes.routes();
export default postRoutes.router;
那么,出了什么问题?
我的package.json文件:
{
"name": "typescript-express-server",
"version": "1.0.0",
"main": "./build/index.js",
"license": "MIT",
"scripts": {
"start:server": "nodemon --watch ./build/index.js",
"watch:build": "tsc --watch"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "1.18.2",
"compression": "1.7.2",
"cookie-parser": "1.4.3",
"cors": "2.8.4",
"dotenv": "5.0.1",
"express": "4.16.3",
"helmet": "3.12.0",
"lodash": "4.17.5",
"mongoose": "5.0.15",
"morgan": "1.9.0"
},
"devDependencies": {
"@types/body-parser": "1.16.8",
"@types/cookie-parser": "1.4.1",
"@types/cors": "2.8.4",
"@types/express": "4.11.1",
"@types/mongoose": "4.7.32",
"@types/node": "9.6.6",
"nodemon": "1.17.3",
"tslint": "5.9.1",
"typescript": "2.8.3"
}
}
答案 0 :(得分:0)
待办事项
const { router } = postRoutes
export default router
在export default postRoutes.router
中,TS假定postRoutes
是命名空间。