Currently, I am setting up my own TypeScript Express project and aiming to abstract the code for better organization. In my app.ts file, the code looks like this:
import express from 'express'
const app = express();
const port = 3000;
require('./routes')(app)
app.listen(port, err => {
if (err) {
return console.error(err);
}
return console.log(`server is listening on ${port}`);
});
export default app
I am trying to segregate all routes configured in this app into a separate folder for easier navigation.
In my routes.ts file, the code is as follows:
const testController = require('./controllers/test')
import app from './app';
module.exports = (app) => {
app.get('/test',
testController.testingRoute)
}
The issue arises when attempting to run the script or analyze the code, it displays an error stating
Parameter 'app' implicitly has an 'any' type
. If I try to specify app:app
, another error pops up saying 'app' refers to a value, but is being used as a type here.
I want to refrain from disabling type checking in tsconfig, as I believe TypeScript's type system is integral to its functionality. How should I go about tackling this problem?