Rhushikesh
Rhushikesh

Reputation: 3700

getting error Property '...' does not exist on type 'typeof "...."'

I am developing an app in node js using typescript and use the gulp transpiler in commonjs mode.

I have wrote a homeController.ts as:

let homeController={
     getIndex:(req,res)=>{
        res.send('Hello world'); //Compiles the file named "index" in the views directory (`/views`) using the view engine (Jade).
    },
}
export default homeController;

and i have a separate route file for routing as route.ts

import  home  =require('../controller/homeController');
import express = require('express');

let router = express.Router();

router.get('/',home.getIndex);

module.exports = router;

and import it in server file as

import  routes = require('./routes/route');

and route it as

app.use('/api', routes);

but when gulp compile these file it give the error

enter image description here

please correct me if i'm doing any mistake.

Upvotes: 3

Views: 4950

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 220964

Your homeController.ts file exports an object with the shape { default: { getIndex: ... } }. It does not have a top-level getIndex property.

You probably want to use export = homeController instead of export default homeController. They are not equivalent.

Upvotes: 4

Related Questions