Andrey
Andrey

Reputation: 76

error TS2503: Cannot find my namespace

I am running tsc --watch (compiling typescript into javascript) and catching warning:

router/PostRouter.ts(103,16): error TS2503: Cannot find namespace 'postRoutes'.

In my .ts file in the 103 string:

const postRoutes = new PostRouter();
postRoutes.routes();
export default postRoutes.router;

So, what's wrong?


My package.json file:

{
  "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"
  }
}

enter image description here

Upvotes: 1

Views: 3918

Answers (1)

Tyler Sebastian
Tyler Sebastian

Reputation: 9448

Do

const { router } = postRoutes

export default router

in export default postRoutes.router, TS assumes that postRoutes is a namespace.

Upvotes: 2

Related Questions