[英]error TS2503: Cannot find my namespace
I am running tsc --watch (compiling typescript into javascript) and catching warning: 我正在运行tsc --watch (将打字稿编译为javascript)并捕获警告:
router/PostRouter.ts(103,16): error TS2503: Cannot find namespace 'postRoutes'.
In my .ts file in the 103 string: 在我的.ts文件中的103字符串中:
const postRoutes = new PostRouter();
postRoutes.routes();
export default postRoutes.router;
So, what's wrong? 那怎么了
My package.json file: 我的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"
}
}
Do 做
const { router } = postRoutes
export default router
in export default postRoutes.router
, TS assumes that postRoutes
is a namespace. 在
export default postRoutes.router
,TS假定postRoutes
是一个名称空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.