'what type do I use for app in express typescript
I'm exporting controllers in an index.ts, does anyone know what type do I use when passing app as a parameter in line 7?
import userController from "./userController.js"
import getController from "./getController.js"
import productController from "./productController.js"
const exportArr = [userController, getController, productController]
export default (app: any) => {
exportArr.forEach(controller => controller(app))
}
Solution 1:[1]
Make sure you install express types npm install @types/express and in your .ts file import {Application} from 'express'
Your code would look like this:
import { Application } from "express";
import userController from "./userController.js"
import getController from "./getController.js"
import productController from "./productController.js"
const exportArr = [userController, getController, productController]
export default (app: Application) => {
exportArr.forEach(controller => controller(app))
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Kerr |
