Home > Enterprise >  what type do I use for app in express typescript
what type do I use for app in express typescript

Time:05-19

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))
}

CodePudding user response:

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))
}
  • Related