I'm exporting a function from a controller file:
import adminSaveSnippet from './admin/adminSaveSnippet';
exports.saveSnippet = adminSaveSnippet;
I am importing the function into my routing file:
import * as express from 'express';
const adminRouter = express.Router();
import * as admin from '../controllers/adminControllers';
adminRouter.put('/save/snippet', admin['saveSnippet']);
export default adminRouter;
I can access the saveSnippet
function in admin
via admin['saveSnippet']
but when I use dot notation admin.saveSnippet
I get the following error:
src/routes/admin.ts:5:40 - error TS2339: Property 'saveSnippet' does not exist on type 'typeof import(".../src/controllers/adminControllers")'.
I am not really sure what is going on. I am not using any irregular identifiers and I have tried several different ways of exporting the function (e.g., import { saveSnippet } from '../controllers/adminControllers'
) but still get the same error.
For completeness here is my adminSaveSnippet file:
export default function adminSaveSnippet (_req, res) {
console.log('here');
res.send('saved').status(200);
}